Break Statement in Java

Break Statement in Java

Break Statement in Java

When a program excutes break statement within a loop, that loop will terminate.

syntax:

jump_statement

break;

Example:

public class Demo {
public static void main(String[] args) {
boolean res = false;
for (int i = 0; i < 50; i++) {
if (i == 10) {
res = true;
break;
}
}
if (res)
System.out.println("we found 10");
}
}

Output:

We found 10

Leave a Reply

Your email address will not be published. Required fields are marked *

Looking for Online Training