Entry Controlled Loop: Unfixed Iteration
Learn about the contribution of branching statements on controlling the behavior of a program in this lesson.
Coding example: 58
The following example deals with another interesting part of code statements, branching statements. By using continue and break keywords, we can control the movement of a loop. First, see the example provided below:
Java
public class ExampleFiftyEight {public static void main(String[] args) {System.out.println("Continue statement: ");//continue statement tells the control to skip the current statement//the loop executes the remaining statementfor(int i = 0; i < 5; i++){if(i == 2){continue;}System.out.println(i);}System.out.println("Break statement: ");for(int i = 0; i < 5; i++){if(i == 2){break;//loop terminates when this condition is true}System.out.println(i);}}}
Code explanation
In the first case, the continue keyword skips a certain value and the loop continues. In the second case, when the iteration matches the ...
Ask