1/8
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
Java Loop Statements
• A loop repeats a group of statements.
• Java has several statements for controlling loops.
The while Statement
• A while loop repeats its body while a boolean expression is true.
• The body of a while loop often is a compound statement.
• Do not write a semicolon after the beginning of a while statement.
• while(boolean_expression){
First_Statement
Second_Statement
....
Last_Statement
}
The do-while Statement
• A do-while loops also repeats its body while a boolean expression is true.
• The body of a do-while loop often is compound statement.
• A do-while loop repeats its body at least once.
• do{
First_Statement
Second_Statement
....
Last_Statement
}while(boolean_expression);
Infinite Loops
• An infinite loop executes repeatedly due to an error in logic.
• Learn how to force a program to stop running.
Nested Loops
• The body of one loop can contain another loop.
The for Statement
• A for statement groups the major aspects of a loop.
• A for loop is logically equivalent to a while loop.
• Do not write a semicolon after the beginning of a for statement.
Declaring Variables Within a for Statement
• A variable's scope is where it has meaning in a program.
Using a Comma in a for Statement (Optional)
• A comma can separate multiple initializations in a for statement.
The for-each Statement
• A for-each statement iterates for each item in a data collection.