Java programming language provides the following types of loop to handle looping requirements.
|
Sr.No. |
Loop & Description |
|
1 |
Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. The syntax of a while loop is − while(condition) { // Statements } |
|
2 |
Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable. for(initialization; condition; update) { // Statements } |
|
3 |
Like a while statement, except that it tests the condition at the end of the loop body. do { // Statements }while(condition); |
Loop Control Statements
Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed. Java supports the following control statements.
|
Sr.No. |
Control Statement & Description |
|
1 |
Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch. The syntax of a break is a single statement inside any loop − break; |
|
2 |
Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. The syntax of a continue is a single statement inside any loop − continue; |
Watch on YouTube