16-Oct-15 Loops in Methods And compound conditions.

Slides:



Advertisements
Similar presentations
Using Jeroo Dianne Meskauskas
Advertisements

13-Jun-14 OOP features of Jeroo. Overview In this presentation we will discuss these topics: OOP terminology Jeroo syntax constructors methods.
While loops.
Python Programming Language
11-May-15 Control Structures part 2. Overview Control structures cause the program to repeat a section of code or choose between different sections of.
Programming in Jessica By Joaquin Vila Prepared by Shirley White Illinois State University Applied Computer Science Department.
SIMPLE PROGRAMS Jeroo – Chapter 4 –. Basic Concepts Jeroo (Java/C++/object-oriented) programing style is case-sensative. Be consistent in coding Logic.
SLIDE SHOW INSTRUCTIONS This presentation is completely under your control. This lesson will show only one step at a time, to see the next step you must.
Programming Concept #2 Iteration. Is just a fancy way of saying that you would like something to repeat more than one time. It is used in any modern programming.
Prof. Bodik CS 164 Lecture 61 Building a Parser II CS164 3:30-5:00 TT 10 Evans.
CS1061: C Programming Lecture 8: Repetition A. O’Riordan, 2004.
© 2005 by Prentice Hall Chapter 9 Structuring System Requirements: Logic Modeling Modern Systems Analysis and Design Fourth Edition.
Sentinel Logic Assumes while loops and input statements.
9-Aug-15 Vocabulary. Programming Vocabulary Watch closely, you might even want to take some notes. There’s a short quiz at the end of this presentation!
SLIDE SHOW INSTRUCTIONS This presentation is completely under your control. This lesson will show only one step at a time, to see the next step you must.
Box and Whisker Plots. Order numbers 3, 5, 4, 2, 1, 6, 8, 11, 14, 13, 6, 9, 10, 7 First, order your numbers from least to greatest: 1, 2, 3, 4, 5, 6,
Chapter 9 Structuring System Requirements: Logic Modeling
30-Aug-15 Using Jeroo. Overview In this presentation we will discuss: What is Jeroo? Where did it come from? Why use it? How it works. Your first assignments.
Using Jeroo To Teach Object-Oriented Concepts By Christian Digout.
17-Sep-15 Using Jeroo. Overview In this presentation we will discuss: What is Jeroo? Where did it come from? Why use it? How it works. Your first assignments.
5-Oct-15 Introduction and Code. Overview In this presentation we will discuss: What is Jeroo? Where can you get it? The story and syntax of Jeroo How.
Finding Roots Composite Numbers STEP 1: Find all the factors of a number.
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
25-Oct-15 Jeroo Code. Overview In this presentation we will discuss: How to write code in Jeroo How to run a Jeroo program.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
13-Nov-15 Control Structures. Overview Without control structures, everything happens in sequence, the same way every time Jeroo has two basic control.
Type your question here. Type Answer Type your question here. Type Answer.
ITEC 352 Lecture 3 Low level components(2). Low-level components Review Electricity Transistors Gates Really simple circuit.
Division Using multiplication and repeated subtraction.
16-Dec-15 Control Structures VB. Overview Without control structures, everything happens in sequence, the same way every time Jeroo has two basic control.
Robot Programming. Programming Behaviors Behaviors describe the actions and decisions of your robot.
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
17-Feb-16 Methods. Overview In this presentation we will discuss these 4 topics: Main method vs. Jeroo methods Choosing behaviors to turn into methods.
Selection structures in Jeroo! if, if else, if, else if, else if, else.
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
11-Jun-16 Algorithms 2.2. Overview In this presentation we will discuss: What is an algorithm? 5 steps in developing an algorithm A Jeroo example.
Introduction to Jeroo a small object oriented programming language.
Methods 9-Mar-17.
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
Control Structures part 2
Chapter 9 Structuring System Requirements: Logic Modeling
Jeroo Code 18-Jul-18.
2.2 Algorithms 21-Jul-18.
OOP features of Jeroo 8-Nov-18.
a small object oriented programming language.
Chapter 9 Structuring System Requirements: Logic Modeling
Karnaugh Maps Topics covered in this presentation: Karnaugh Maps
Chapter 9 Structuring System Requirements: Logic Modeling
CSC215 Lecture Flow Control.
CSC215 Lecture Control Flow.
Introduction and Code 18-Jan-19.
Overview Introduction to Jeroo: What is Jeroo? Where did it come from?
Box and Whisker Plots.
SSEA Computer Science: Track A
Control Structures 5-Apr-19.
Chapter 9 Structuring System Requirements: Logic Modeling
Control Structures part 2
Chapter 9 Structuring System Requirements: Logic Modeling
Control Structures 12-May-19.
CSC215 Lecture Control Flow.
2.2 Algorithms 26-Jun-19.
OOP features of Jeroo 3-Jul-19.
Indentation & Comments
Control Structures VB part 2
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
IF 1-Jul-19.
He must do his homework.. He must do his homework.
Jeroo Code 7-Sep-19.
Presentation transcript:

16-Oct-15 Loops in Methods And compound conditions

Overview Loops can be used in the main method and in Jeroo methods They work the same way, only the syntax is different. Compound conditions allow for more complicated choices.

Using a while loop in a Jeroo method Assume that a Jeroo named Kim is facing a line of flowers ahead. Have Kim pick all of those flowers, and stop as soon as there is no flower directly ahead. After picking all of the flowers, Kim should turn to the left. while( kim.isFlower(AHEAD) ) { kim.hop(); kim.pick(); } kim.turn(LEFT); How would this be written as part of a method?

method pickRow() { while(isFlower(AHEAD)) { hop(); pick(); } turn(LEFT); } Rewritten As part of a method The main program would be: method main() { Jeroo kim = new Jeroo(); kim.pickRow(); }

Simple and Compound Conditions A simple condition has one part. In the Jeroo language, a simple condition is formed by invoking a single sensor method. Examples: tiffany.isClear(RIGHT) walter.isFacing(EAST) A compound condition uses logical operators. The Jeroo language contains the three most commonly used logical operators: ! (NOT) ie: !Tiffany.isClear(RIGHT) && (AND) ie: Tiffany.isClear(RIGHT) && Tiffany.isClear(LEFT) || (OR) ie: Tiffany.hasFlower() || Tiffany.isClear(AHEAD)

Compound condition examples Boolean Expression (Java-style) & English Translation ! bob.isNet(AHEAD) There is not a net ahead of Bob bob.hasFlower() && bob.isClear(LEFT) Bob has at least one flower and there is nothing in the cell immediately to the left of Bob. bob.isWater(AHEAD) || bob.isWater(RIGHT) There is water ahead or to the right of Bob, or both Notice the COMPLETE CONDITIONS on both sides of the OR bob.isFacing(WEST) && ( ! bob.isNet(AHEAD) ) Bob is facing west and there is no net ahead Use these examples to write compound conditions

The Problem: Remove all the nets on Jessica’s right side as she crosses the island. Question: How do you know that a Jeroo has reached the end of the island? How do you say “ keep hopping until you reach the end of the island”? How do you say “keep removing nets until you reach the end of the island”? Answer: there is water ahead while (!isWater(AHEAD)) { hop(); } while(!isWater(AHEAD)) { // put the code here to // remove a net if there is one. } Some questions:

The End