Inside two nested for loops, a break statement in the body of the inner loop terminates what?
Correct answer
A. Only the innermost loop that lexically encloses the break
19 views
A. Only the innermost loop that lexically encloses the break
19 views
break transfers control to the statement following the smallest enclosing switch or loop, so in nested loops it exits only the inner one. Leaving several levels at once needs a flag tested in the outer condition or a goto to a label after the outer loop. continue differs again by skipping to the next iteration of the innermost loop rather than leaving it.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is A? Ask here and get an explanation.