Jump statements: break, continue, goto, return — C++ MCQs

30
Score: 0
Attempted: 0/30
1. What will be the output of this code?
for(int i = 1; i <= 5; i++) {
if(i == 3) break;
cout << i;
}




2. What will the code print?
for(int i = 1; i <= 5; i++) {
if(i == 3) continue;
cout << i;
}




3. What is the output?
int i = 0;
while(i < 5) {
if(i == 2) break;
cout << i;
i++;
}




4. What happens when the following code runs?
int i = 0;
while(i < 5) {
i++;
if(i == 3) continue;
cout << i;
}




5. What will be printed?
for(int i = 1; i <= 3; i++) {
for(int j = 1; j <= 3; j++) {
if(j == 2) break;
cout << j;
}
}




6. Output of this program:
int i = 1;
while(i <= 5) {
if(i == 4) break;
cout << i;
i++;
}




7. What happens when this code runs?
int i = 0;
do {
if(i == 2) break;
cout << i;
i++;
} while(i < 5);




8. What is the output of this loop?
for(int i = 1; i <= 4; i++) {
if(i == 3) continue;
cout << i;
}




9. What will be printed?
int i = 1;
while(i <= 5) {
if(i == 2) {
i++;
continue;
}
cout << i;
i++;
}




10. What is the output?
for(int i = 1; i <= 5; i++) {
if(i == 4) return 0;
cout << i;
}




11. What will happen in this code?
for(int i = 1; i <= 5; i++) {
if(i == 6) return 0;
cout << i;
}




12. What is the result of this program?
int i = 1;
while(i <= 3) {
if(i == 2) goto end;
cout << i;
i++;
}
end:
cout << "Done";




13. What happens here?
int x = 1;
label:
cout << x;
x++;
if(x <= 3) goto label;




14. What will the output be?
int i = 1;
while(i <= 5) {
if(i == 3) goto end;
cout << i;
i++;
}
end:
cout << "Stop";




15. Output of this code:
int i = 1;
do {
if(i == 2) goto label;
cout << i;
i++;
} while(i < 4);
label:
cout << "End";




16. What is printed?
int i = 1;
do {
cout << i;
if(i == 2) break;
i++;
} while(i <= 4);




17. What will the program print?
for(int i = 1; i <= 5; i++) {
if(i == 3) continue;
if(i == 5) break;
cout << i;
}




18. What will be displayed?
int x = 0;
while(x < 5) {
if(x == 3) goto end;
cout << x;
x++;
}
end:
cout << "Done";




19. What happens in this program?
int i = 1;
while(i <= 5) {
if(i == 3) break;
cout << i;
i++;
}
cout << i;




20. What will the output be?
for(int i = 1; i <= 5; i++) {
if(i == 4) break;
cout << i;
}




21. Output of this program:
int i = 1;
while(i <= 5) {
if(i == 2) { i++; continue; }
cout << i;
i++;
}




22. What will happen in this code?
int x = 5;
if(x > 0) return 0;
cout << "Hello";




23. What is the output?
for(int i = 1; i <= 5; i++) {
if(i == 2) goto label;
cout << i;
}
label:
cout << "End";




24. What will the following print?
int i = 1;
label:
cout << i;
i++;
if(i <= 3) goto label;




25. Identify the output:
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
if(j == 1) continue;
cout << j;
}
}




26. What happens?
int i = 1;
do {
if(i == 3) continue;
cout << i;
i++;
} while(i <= 5);




27. What is the result?
for(int i = 1; i <= 4; i++) {
if(i == 2) continue;
if(i == 3) break;
cout << i;
}




28. What will be the output?
int i = 0;
while(i < 5) {
i++;
if(i == 4) goto end;
cout << i;
}
end:
cout << "Stop";




29. What happens?
for(int i = 1; i <= 3; i++) {
if(i == 2) goto label;
cout << i;
}
label:
cout << "X";




30. What will print?
int i = 1;
do {
cout << i;
if(i == 2) break;
i++;
} while(i < 4);




Contents Copyrights Reserved By T4Tutorials