Download presentation
Presentation is loading. Please wait.
Published byLanny Darmadi Modified over 5 years ago
1
Seating “chart” Front - Screen 3 2 4 4 rows 1 5 6 Back DOOR
2
Follow up from lab See Magic8Ball.java “solution”
Issues that you ran into.
3
Code examples Loopy.java
Loops Code examples Loopy.java
4
Why loops? Where have we wanted to use a loop?
What kinds of problems lend themselves to iteration? What do Java loop structures look like?
5
4 parts to a loop Initialization – getting it ready
Decision – Do I continue the loop – boolean expression Body – What do I want to accomplish in a loop Update – How do I approach the false condition to exit the loop?
6
The while loop Flowchart
statement(s) true boolean expression? false while loops are indeterminant loops, we execute until a condition is met and not for any pre – determined number of times. while (result < 10) { ….. do something } Another name is precondition loop – You evaluate the condition before executing the body.
7
The while loop Flowchart
statement(s) true boolean expression? false Another name is precondition loop – You evaluate the condition before executing the body.
8
The while loop Flowchart
statement(s) true boolean expression? false Another name is precondition loop – You evaluate the condition before executing the body.
9
The while loop Flowchart
statement(s) true boolean expression? false Another name is precondition loop – You evaluate the condition before executing the body.
10
The do-while Loop Flowchart
statement(s) true boolean expression? false do { … statements } while (condition); Another name is post condition loop – You evaluate the condition after executing the body.
11
The do-while Loop Flowchart
statement(s) true boolean expression? false Another name is post condition loop – You evaluate the condition after executing the body.
12
The do-while Loop Flowchart
statement(s) true boolean expression? false Another name is post condition loop – You evaluate the condition after executing the body.
13
The do-while Loop Flowchart
statement(s) true boolean expression? false Another name is post condition loop – You evaluate the condition after executing the body.
14
The for Loop Flowchart statement(s) true boolean expression? false
update for (int ii = 0; ii < 10; ii++) { … statements } In a for loop, the initialization, boolean expression and update are combined in one structure. Another name is counted loop – You typically will execute a for loop based on some counter. A for loop is also a precondition loop.
15
Code example Loopy.java Some terms loop control variable
precondition loop post condition loop counted loop
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.