Class 23 - Flow Control in Java, continued 1 Goals for...

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

View Full Document Right Arrow Icon
Flow Control in Java, continued 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Goals for Today n Learn how to use the while loop n Learn how to use the for loop n Learn how to use the do loop 2 MGMT 29000
Background image of page 2
Repetitive Execution n Program execution flows sequentially by default n if and switch perform statements selectively n Repetitive execution: control flows in loops n Three repetition statements: while , for , and do 3 MGMT 29000
Background image of page 3

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

View Full DocumentRight Arrow Icon
Java’s while Statement n Used for processing a series of values n Input loops: read and process a series of values n Sentinel-controlled input loops ¨ Utilize a sentinel (invalid value) to falsify a condition 4 MGMT 29000
Background image of page 4
Java’s while Statement (continued) MGMT 29000 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
Java’s for Statement n Repetition structure for solving counting problems n Counting input loop ¨ Simpler design than the sentinel-controlled input loop ¨ Provides repetition when number of inputs is fixed n Illustration: computing the city’s air pollution index ¨ A for loop counts from 1 to NUM_READINGS ¨ Each iteration gets a reading and adds it to sum ¨ After loop terminates, index is computed and output n Java’s for loop is very flexible ¨ Example: the Java for loop can count down MGMT 29000 6
Background image of page 6
for Statement (continued) MGMT 29000 7
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 04/04/2012 for the course MGMT 290 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 22

Class 23 - Flow Control in Java, continued 1 Goals for...

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