lec07 - Lecture 7 Repetition while do-while for (Savitch...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
CS125 Course Notes Lecture 7, Slide 1 Lecture 7 Repetition while do-while for (Savitch 3.2)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 7, Slide 2 Loop • A portion of a program that repeats a (compound) statement. Iteration – one repetition of the contents of the loop.
Background image of page 2
CS125 Course Notes Lecture 7, Slide 3 While loop • Repeats body as long as a boolean expression is true. • No set number of repetitions. • Body can run zero times.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 7, Slide 4 While loop continued • Syntax: while ( Boolean_Expression ) { Body_Statements; }
Background image of page 4
CS125 Course Notes Lecture 7, Slide 5 While loop example // Assume myScanner properly // initialized int cookiesLeft = myScanner.getInt(); while (cookiesLeft > 0) { System.out.println(“Yummy cookies!”); cookiesLeft--; }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS125 Course Notes Lecture 7, Slide 6 Another while loop example // Assume number initialized while (number % 5 != 0) { System.out.println(number+” is not divisible by 5.”); number++; }
Background image of page 6
CS125 Course Notes
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/27/2009 for the course MATH 135 taught by Professor Andrewchilds during the Fall '08 term at Waterloo.

Page1 / 16

lec07 - Lecture 7 Repetition while do-while for (Savitch...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online