In: Computer Science
Choose the correct option to match the command descriptions below:
The ..(1).. command passes control to the next iteration of a for or while loop,
and skips any remaining statements in the body of the loop for the current iteration.
The ..(2).. command terminates execution of for or while loops. Statements in the loop that appear after
this command are not executed.
(1)end
(2) continue
(1) continue
(2) terminate
(1) continue
(2) break
(1) break
(2) terminate
(1) break
(2) continue
The continue command passes control to the next iteration of a for or while loop, and skips any remaining statements in the body of the loop for the current iteration.
Explanation :
A continue command skips or jumps the current iteration and goes to the next iteration in a for or while loop.
For example consider , following example
for(i=1; i<=5; i++)
{
if(i == 3) /* when i=3 then we skip it */
{
continue;
}
printf("%d ", i);
}
The Output will be : 1 2 4 5
3 gets missed in Output as we kept continue.
The break command terminates execution of for or while loops. Statements in the loop that appear after this command are not executed.
Explanation :
A break is used to come out of loop or break out of any loop it may be for or while.
For example:
i = 1
while ( i < = 5)
{
if ( i == 4) /* when i=4 then we exit the current loop */
{
break;
}
printf("%d ", i);
i = i + 1;
}
Output will be : 1 2 3
4 5 will not be printed because we exit the loop when we arrive at 4