Presentation is loading. Please wait.

Presentation is loading. Please wait.

A LESSON IN LOOPING What is a loop?

Similar presentations


Presentation on theme: "A LESSON IN LOOPING What is a loop?"— Presentation transcript:

1 A LESSON IN LOOPING What is a loop? A portion of a program that repeats a statement or group of statements

2 while statement (while-loop)
TYPES OF LOOPS while statement (while-loop) Action that is coded in braces (body of the while loop) is repeated (in order) until the condition of the while loop is met. Repetition is called an iteration of the loop

3 CODING EXAMPLE How many greetings? Ask the user how many ‘hello’ statements they want to print and execute. Print ‘That’s All!’ when finished.

4 SYNTAX while(condition) { Insert code to repeat here }

5 EXAMPLE

6 TYPES OF LOOPS do while statement Similar to while statement, except that the loop body is always executed at least once. Do ‘this’ (at least once), while ‘this’ is true

7 Hello! Do you want another?
CODING EXAMPLE Hello! Do you want another? Greet the user – ‘Hello!’, ask if they would like another greeting – input 1(yes) or 2(no)? Execute until user enters 2(no)

8 SYNTAX do { Insert code to repeat here }while(condition);

9 EXAMPLE


Download ppt "A LESSON IN LOOPING What is a loop?"

Similar presentations


Ads by Google