Today i have learnt about the while loop,do-while loop and the decision making statements like break and continue statement.
June 20,2016
Java While Loop
The Java while loop is used to iterate a part of the program several times. If the number of iteration is not fixed, it is recommended to use while loop.
Syntax:
- while(condition){
- //code to be executed
- }
Java do-while Loop
The Java do-while loop is used to iterate a part of the program several times. If the number of iteration is not fixed and you must have to execute the loop at least once, it is recommended to use do-while loop.
The Java do-while loop is executed at least once because condition is checked after loop body.
Syntax:
- do{
- //code to be executed
- }while(condition);
Java Break Statement
The Java break is used to break loop or switch statement. It breaks the current flow of the program at specified condition. In case of inner loop, it breaks only inner loop.
Syntax:
- jump-statement;
- break;
Java Continue Statement
The Java continue statement is used to continue loop. It continues the current flow of the program and skips the remaining code at specified condition. In case of inner loop, it continues only inner loop.
Syntax:
- jump-statement;
- continue;