24.0k views
0 votes
The break statement is used with which statement?

A)at
B)for
C)nested if
D)switch

User Big Sam
by
8.8k points

1 Answer

2 votes

Answer:

B) for

Step-by-step explanation:

The break statement is used in looping constructs to break out of the loop.

for is an example of a construct used for looping n Java.

Consider the example:

for(int i=0;i<10;o++){

System.out.print(i);

if(i==5)break;

}

In this case the output will consist of 012345 .

When loop variable i is equal to 5, the if condition will be satisfied and the loop breaks due to break statement.

Note that break is also used with switch...case blocks, but in this case it is more closely tied to the case statement.

User FinnNk
by
7.9k points