16-Dec-15 Control Structures VB. Overview Without control structures, everything happens in sequence, the same way every time Jeroo has two basic control.

Slides:



Advertisements
Similar presentations
13-Jun-14 OOP features of Jeroo. Overview In this presentation we will discuss these topics: OOP terminology Jeroo syntax constructors methods.
Advertisements

1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
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.
Do Loops A Do..Loop terminates based on a condition that is specified Execution of a Do..Loop continues while a condition is True or until a condition.
INTRODUCTION TO PYTHON PART 3 - LOOPS AND CONDITIONAL LOGIC CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
UNIT II Decision Making And Branching Decision Making And Looping
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
Python Control Flow statements There are three control flow statements in Python - if, for and while.
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.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Lecture 4 C Program Control Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
16-Oct-15 Loops in Methods And compound conditions.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
25-Oct-15 Jeroo Code. Overview In this presentation we will discuss: How to write code in Jeroo How to run a Jeroo program.
Controlling Execution Dong Shao, Nanjing Unviersity.
ㅎㅎ 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,
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
13-Nov-15 Control Structures. Overview Without control structures, everything happens in sequence, the same way every time Jeroo has two basic control.
Pascal Programming Iteration (looping) Carl Smith National Certificate Unit 4.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Matlab tutorial course Lesson 4: Writing your own functions: programming constructs
While and If-Else Loops ROBOTC Software. While Loops While loop is a structure within ROBOTC Allows a section of code to be repeated as long as a certain.
Obj: Programming: Simple Control Structures HW: Read section 3 – 2 AC3 D2 Do Now: 1.Log on to Alice. Open the file firstEncounter.a2w located in the folder.
CSI 3125, Preliminaries, page 1 Control Statements.
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.
Programming: Simple Control Structures Sec 46 Web Design.
Selection structures in Jeroo! if, if else, if, else if, else if, else.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Control structures in C by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
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.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
PYTHON WHILE LOOPS. What you know While something is true, repeat your action(s) Example: While you are not facing a wall, walk forward While you are.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
C Program Control September 15, OBJECTIVES The essentials of counter-controlled repetition. To use the for and do...while repetition statements.
PH2150 Scientific Computing Skills Control Structures in Python In general, statements are executed sequentially, top to bottom. There are many instances.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
Methods 9-Mar-17.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
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
Programming: Simple Control Structures
Programming: Simple Control Structures
Jeroo Code 18-Jul-18.
If, else, elif.
JavaScript: Control Statements.
Control Structures – Selection
Loop Control Structure.
IF if (condition) { Process… }
Introduction and Code 18-Jan-19.
Computer Science Core Concepts
Control Structures 5-Apr-19.
Control Structures part 2
ASP control structure BRANCHING STATEMENTS
Control Structures 12-May-19.
Python While Loops.
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
Control Structures VB part 2
IF 1-Jul-19.
Jeroo Code 7-Sep-19.
Presentation transcript:

16-Dec-15 Control Structures VB

Overview Without control structures, everything happens in sequence, the same way every time Jeroo has two basic control structures while ( to repeat statements ) if (includes: if-else, cascaded if)

Repetition The Jeroo language only contains one repetition structure: the pretest while loop. 1. Execute “some statement” 2. Check the condition if it is true – execute body recheck condition if it is false – terminate loop execute “next statement some statement While condition body of loop End While next statement

While loop notes The pretest while structure (also called a while loop) is used to define a block of code that will be executed repeatedly as long as a specified condition is true. Note: The while structure is not a method, which means that we do not send it as a message to a Jeroo object. Example: while there is a flower ahead of the jeroo named Sam, keep picking them and hopping: while Sam.isFlower(ahead) Sam.hop() Sam.pick() end while it’s called pre-test because first it tests to see if it’s true that there is a flower ahead before picking and hopping

another loop example: Example: while there is not a net ahead of the jeroo named James, keep hopping: while not James.isnet(ahead) James.hop() end while it’s called pre-test because first it tests to see if it’s true that there is NOT a net ahead before hopping

Example problem using loops Assume that a Jeroo named Kim is not standing on a flower, but there is 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() End While Kim.turn(LEFT)

While loop style There are two important things to observe about the coding style. 1. End While marks the end of the loop 2. The statements in the loop are indented. While condition 'statements that comprise the body of the loop End While

The form of a Conditional Statement 1. Execute “some statement” 2. Check the condition true – execute true branch false – skip true branch 3. execute “next statement” some statement if condition THEN do if true End If next statement

If statement style There are two important things to observe about the coding style. 1. The conditional statements are indented. 2. The End If is aligned with the start of the word If. If condition Then 'statements that execute if condition is true End If

If Example Have the Jeroo named Jessica check for a net to her right. If there is one, have her disable it and return to her current state. Whether or not she disables a net, Jessica should hop one space ahead. If Jessica.isNet(RIGHT) then Jessica.turn(RIGHT) Jessica.toss() Jessica.turn(LEFT) End If Jessica.hop()

If-else statement 1. Execute “some statement” 2. Check the condition true – execute true branch, skip false branch false – skip true branch, execute false branch 3. execute “next statement” some statement if (condition) Then do if true else do if false End If next statement

If-else statement style There are two important things to observe about the coding style. 1. The End If is aligned with the words if and else. 2. The conditional statements are indented. if( condition ) Then 'statements that execute if condition is true else ' statements that execute if condition is false End If

If-else Example Have the Jeroo named Timmy check for a net straight ahead. If there is one, have him disable it and turn around. If there is not a net straight ahead, Timmy should turn right. After he disables the net and turns around or simply turns right, Timmy must move one space forward. If Timmy.isNet(AHEAD) then Timmy.toss() Timmy.turn(LEFT) else Timmy.turn(RIGHT) End If Timmy.hop() Notice where the code matches the problem description:

Sensor methods In the Jeroo language, the sensor methods are the basic building blocks for creating conditions. The simplest way to create a condition is to invoke a sensor method. hasFlower() Does this Jeroo have any flowers? isFacing( compassDirection ) Is this Jeroo facing in the indicated direction? isFlower( relativeDirection )Is there a flower in the indicated direction? isJeroo( relativeDirection ) Is there another Jeroo in the indicated direction? isNet( relativeDirection ) Is there a net in the indicated direction? isWater( relativeDirection ) Is there water in this direction? isClear( relativeDirection ) Is there a clear space in the indicated direction? A clear space contains no flower, no net, no water, and no Jeroo. Each sensor method is Boolean. It has either a true or a false result. Use these examples to write some Boolean conditions

Cascaded if statement style 3 things about the coding style. 1. The End IF is aligned with the start of the words if and else. 2. Elseif is one word. 3. The other statements are indented. If condition_1 then 'statements that execute if condition_1 is true elseif condition_2 then 'statements to execute when condition_2 is true 'more else if blocks as necessary elseif last_condition then 'statements to execute when last_condition is true else 'statements to execute when all conditions are false End If elseif is 1 word This particular structure is often called a cascaded if. Only one block of code will be executed.

Cascaded if syntax There are 2 important things to observe about this structure 1. There is no limit on the number of else-if blocks. 2. The final else block is optional.

Cascaded if Example Assume that a Jeroo named Louisa is carrying at least one flower. Have her check the cell ahead. If that cell contains a flower, pick it. If that cell contains a net, disable it. If that cell contains water, plant a flower at the current location. If that cell contains another Jeroo, give that Jeroo a flower. Finally, if there is nothing in that cell, have her hop once and turn left. if Louisa.isFlower(AHEAD) then Louisa.hop() Louisa.pick() elseif Louisa.isNet(AHEAD) then Louisa.toss() elseif Louisa.isWater(AHEAD) then Louisa.plant() elseif Louisa.isJeroo(AHEAD) then Louisa.give(AHEAD) else Louisa.hop() Louisa.turn(LEFT) End If

The End