How to use labels in Java code?
Answers
Answered by
0
Java provides two types of branching/control statements namely, break and continue.
The break statement: This statement terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch.
Example:
Following is the example of the break statement. Here we are trying to print elements up to 10 and, using break statement we are terminating the loop when the value in the loop reaches 8.
public class BreakExample { public static void main(String args[]){ for(int i=0; i<10; i++){ if (i==8){ break; } System.out.println("......."+i); } } }
The break statement: This statement terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch.
Example:
Following is the example of the break statement. Here we are trying to print elements up to 10 and, using break statement we are terminating the loop when the value in the loop reaches 8.
public class BreakExample { public static void main(String args[]){ for(int i=0; i<10; i++){ if (i==8){ break; } System.out.println("......."+i); } } }
Similar questions
Computer Science,
7 months ago
Science,
7 months ago
English,
7 months ago
Computer Science,
1 year ago
English,
1 year ago