227k views
3 votes
True or False?

The break statement causes a loop to stop the current iteration and begin
the next one.

1 Answer

1 vote

False.

The different between break and continue instruction is that with break you exit the loop, and with continue you skip to the next iteration.

So, for example, a loop like

for(i = 1; i <= 10; i++){

if(i <= 5){

print(i);

} else {

break;

}

}

will print 1,2,3,4,5, because when i=6 you will enter the else branch and you will exit the loop because of the break instruction.

On the other hand, a loop like

for(i = 1; i <= 10; i++){

if(i % 2 == 0){

print(i);

} else {

continue;

}

}

Will print 2,4,6,8,10, because if i is even you print it, and if i is odd you will simply skip to the next iteration.

User Terence Honles
by
6.4k points