This quiz tests your knowledge of loops in C++. It contains 10 questions.
Question 1
How many times will the loop run?
#include <iostream>
using namespace std;
int main() {
for (i = 0; i < 15; i++) {
cout << i << endl;
}
return 0;
}
14
16
Error
15
Question 2
What will be the output of the following C++ code?
#include <iostream> using namespace std; int main () { int n; for (n = 5; n > 0; n--) { cout << n; if (n == 3) break; } return 0; }
543
5432
54
432
Question 3
Which of the following for loop will not work?
for (int i=0; i<5; i++)
for (int i=5; i<=10; i++)
for (int i=5; i=10; i++)
all of the above
Question 5
How many times the loop will run?
#include <iostream> using namespace std; int main() { int i; for (i = 0; i < 15; i++) { cout << i << endl; } return 0; }
12
15
14
Error
Question 6
What will be the output of the following C++ code?
#include <iostream> using namespace std; int main() { int n = 15; for (;;) cout << n; return 0; }
error
infinite times of printing n
15
none of the mentioned
Question 7
Choose a correct C++ for loop syntax.
for(initalization; condition; inc/dec){ // statements };
for(declaration; condition; incrementoperation){ // statements };
for(declaration; incrementoperation; condition){ // statements };
for(initalization; condition; incrementoperation){ // statements };
Question 8
What is the way to suddenly come out of or quit any loop in C++?
continue; statement
break; statement
leave; statement
quit; statement
Question 9
Choose the type of loop which is guaranteed to execute at-least once?
for loop
while
do-while
None
Question 10
What is the do-while loop also known as?
Entry control
Exit control
Per tested
All of the above
There are 12 questions to complete.