1 / 16

While Loops

While Loops. Chapter 3. Console Input and Output. Input and output interactions with the used are maintained for later inspection. How Did We Get This Box. Right click the input: box. Click edit. How Did We Get This Box. Click the More button. Click console and fill in variable and prompt.

dyani
Download Presentation

While Loops

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. Counting Backwards

  9. 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

  10. Grocery Checkout

  11. Determine the Average

  12. 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

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

  14. Redesign the Grocery Checkout Not using the Exit Loop

  15. High-Low Game

More Related