Programming Fundamentals
Loop’s MCQs
Submitted To:
Mr. Amir Jamshaid
Submitted by:
Javeria Ismail
Roll#: 20
Q1: Choose the correct option.
1. Which of the following can replace a simple if – else construct?
a. Ternary Operator c. Do - While Loop
b. While Loop d. for Loop
2. Which of the following is most suitable for a menu – driven program?
a. Do – While loop c. for loop
b. While loop d. All of these
3. Consider the following statement
for(int i = 0; i<5; i++);
What will be the output?
a. Some garbage value c. 6
b. 5 d. It will generate a compilation error
4. What is the effect of writing a break statement inside a loop?
a. It cancels the remaining iteration. c. it skips particular iteration
b. Program terminates immediately. d. Loop counter is reset.
5. For(; ;)
a. Means the test which is done using some expression is always true
b. Not valid c. Will loop forever
6. Consider the following statement
int x = 22, y = 15
x = (x>y) ? (x+y) : (x-y)
What will be the value of x after execution of these statement?
a. 7 c. 37
b. 22 d. Error. Cannot be executed
7. What will be the output of following:
for (n = 5; n > 0; n--)
{
cout << n;
if (n == 3)
break;
}
a. 54 c. 5432
b. 53 d. 543
8. Which looping process is best used when the number of iterations is known?
a. While c. for
b. Do – while d. All
9. If the variable count exceeds 100, a single statement that prints “Too many” is:
a. if (count<100) cout<<”Too many”;
b. if (count>100) cout>>”Too many”;
c. if (count>100) cout<<”Too many”;
d. none
10. Which one is an entry-controlled loop.
a. Do-while Loop c. for loop
b. While Loop d. Both B and C