Recitation6_new

Recitation6_new - CS 180 Recitation Repetition Statements...

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

View Full Document Right Arrow Icon
CS 180 Recitation Repetition Statements Feb 17, 2012
Background image of page 1

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

View Full DocumentRight Arrow Icon
Repetition/Iteration Statements Used to create loops in code. Loop is a set of instructions that are executed repeatedly until a termination condition is met. while statement do-while statement for statement
Background image of page 2
while statement General form while ( Condition ) { // body of loop } Condition is any Boolean expression. The “body of loop” will be executed as long as the Condition is true. When Condition becomes false, the control passes to the statement immediately after the while statement.
Background image of page 3

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

View Full DocumentRight Arrow Icon
while - Example1 public class WhileExample1 { public static void main(String[] args) { int x = 1; System.out.println("Before Loop"); while (x < 4) { System.out.println(x); x++; } System.out.println("After Loop"); } }
Background image of page 4
while – Example1 cont’d. Output: Before Loop 1 2 3 After Loop
Background image of page 5

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

View Full DocumentRight Arrow Icon
while - Example2 public class WhileExample2 { public static void main(String[] args) { int x = 1; System.out.println("Before Loop"); while (x < 1) { System.out.println(x); x++; } System.out.println("After Loop"); } }
Background image of page 6
Output:
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.

Page1 / 18

Recitation6_new - CS 180 Recitation Repetition Statements...

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