Presentation is loading. Please wait.

Presentation is loading. Please wait.

While Loops Chapter 3.

Similar presentations


Presentation on theme: "While Loops Chapter 3."— Presentation transcript:

1 While Loops Chapter 3

2 Console Input and Output
Input and output interactions with the used are maintained for later inspection.

3 How Did We Get This Box Right click the input: box Click edit

4 How Did We Get This Box Click the More button
Click console and fill in variable and prompt

5 Console Input and Output
Persistent Each line remains in console window To move to new line you must use an end of line symbol

6 LOOPING Used to Perform Same Action Multiple Times

7 While Loops Used to repeat actions
Condition inside the loop remains true Body of the loop executes Condition inside the loop is false Body of the loop does not execute Use a control variable Example Count

8

9 Counting Backwards

10 While Loops and Sentinel Values
Use when you don’t know the number of iterations The user inputs the end Use a special value (sentinel value) to indicate stop

11 Grocery Checkout

12 Determine the Average

13 Exit Loop Causes control to jump out of the loop
Goes to the statement immediately below the loop I am not a big fan of these. You should have another way of exiting the loop. Redesign the code rather than use

14 Grocery Checkout Using Exit Loop
This will be handled very differently in Java

15 Redesign the Grocery Checkout Not using the Exit Loop

16 High-Low Game


Download ppt "While Loops Chapter 3."

Similar presentations


Ads by Google