Computer Science, asked by rohanchaudhary9418, 1 year ago

How to use labels in Java code?

Answers

Answered by hritik38386241
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);       }    } }
Similar questions