1. Home
  2. Computer Science MCQs
  3. C Programming
  4. Inside two nested for loops, a break statement in the body…

Added 30 Nov -0001

Inside two nested for loops, a break statement in the body of the inner loop terminates what?

  1. Only the innermost loop that lexically encloses the break Correct answer
  2. Both loops, since break always leaves the outermost loop
  3. The entire function, returning control to the caller
  4. The current iteration of both loops, then continues with the next outer iteration

Correct answer

A. Only the innermost loop that lexically encloses the break

19 views

MCQSEXAM

Explanation

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.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs