Machine-translated by Google. Questions are authored in English.
Top

Control Instructions Questions and Answers

Direction for [ Question No: 1 To 1 ] :


Assertion – Reason type questions :
The following items consist of two statements, one labelled the ‘Assertion (A)’ and the other labelled the ‘Reason (R)’. You are to examine these two statements and decide if the Assertion (A) and the Reason (R) are individually true and if so, whether the Reason is a correct explanation of the Assertion. Select your answers to these items using the codes given below and mark your answer sheet accordingly.

Codes :
(A) Both (A) and (R) are true and (R) is the correct explanation of (A).
(B) Both (A) and (R) are true but (R) is not the correct explanation of (A).
(C) (A) is true and (R) is false.
(D) (A) is false and (R) is true.

1.

Assertion (A) : The break; statement is used to exit from if statement.

Reason (R) : In while (1) loop break; statement is put at the end of a loop.

Exam Year(s)

UGC NET - 2012,

Answer: C

The key treats the assertion as true and the reason as false. The break statement is used to leave a loop or a switch, and it is commonly placed under an if statement so that the loop is left when the condition holds, which is the sense of exiting from an if statement in the key. The reason says that in a while(1) loop the break statement is put at the end of the loop, which is false, because it is put inside a condition anywhere in the loop body, otherwise the loop would end after the first pass with no test. The answer is that (A) is true and (R) is false.

Please log in or register to report this question.

Direction for [ Question No: 2 To 2 ] :

Directions : In the following questions, match List - I and List - II and select the correct answer using the codes given below the lists :

2.

List - IList - II
a. while (1)i. on-off control implementation
b. paranthesisii. infinite
c. Switch-caseiii. change of precedence
d. If-theniv. multiple processing

Codes : a b c d

Exam Year(s)

UGC NET - 2012,

Answer: C

The matching is: a while (1) with infinite (ii), b parenthesis with change of precedence (iii), c switch-case with multiple processing (iv), d if-then with on-off control implementation (i), the code ii iii iv i (option C).

A while loop with the condition 1 never ends, brackets override the precedence, a switch statement picks one of many cases, and an if-then statement gives an on-off decision. Options A, B and D mismatch the loop or the brackets.

Please log in or register to report this question.

3.

Consider the following C program:

#include \(\lt\)stdio.h\(\gt\)
int main(){
int a = 6;
int b = 0;
while(a \(\lt\) 10) {
a = a / 12 + 1;
a += b;}
printf(”%d”, a);
return 0;}

Which one of the following statements is CORRECT?

Exam Year(s)

GATE CS - 2024,

Answer: C

The program gets stuck in an infinite loop.

Trace it. a = 6, b = 0, and 6 \(\lt\) 10, so the loop runs: a = 6 / 12 + 1 = 0 + 1 = 1 (integer division), then a += 0 leaves a = 1. Now 1 \(\lt\) 10, so the loop runs again: a = 1 / 12 + 1 = 1, and a stays 1.

From then on a is 1 on every pass, so the condition a \(\lt\) 10 never becomes false and printf is never reached. The program prints nothing, so 9, 10 and 6 are all wrong; 6 would require the loop body never to run.

Please log in or register to report this question.

4.

foreach instruction is used in :

Exam Year(s)

MH SET - 2018, SET Exam - 2018,

Answer: B

The foreach statement is used in Perl.

Perl's foreach loop runs through each element of a list or array in turn, setting a loop variable to each element and executing the block once for it. It is the natural way to process every item of an array or every key of a hash.

Pascal has for ... to and while loops, FORTRAN has the DO loop, and COBOL uses the PERFORM statement for repetition. None of them has a foreach instruction.

Please log in or register to report this question.

5.

A do-while loop always executes its loop body at least ..................

Exam Year(s)

MH SET - 2018, SET Exam - 2018,

Answer: C

A do-while loop executes its body at least once.

In do { ... } while (condition); the condition is tested after the body has run. So the body runs once before the condition is ever checked, even if the condition is false from the start. A while loop tests first and may execute zero times, which is the key difference between the two.

Nothing in the construct forces a second, third or fourth pass: if the condition is false after the first pass, the loop ends.

Please log in or register to report this question.

6.

Consider the following 'C' program fragment :

int i = 5;
do
{
    putchar (i + 100);
    printf ("%d", i...);
} while (i);

results in the following output :

Exam Year(s)

MH SET - 2023, SET Exam - 2023,

Answer: C

The fragment results in an error message.

The argument to printf is written i..., which is not a valid C expression, so the compiler reports a syntax error and no output is produced.

The other options are the trap. If the argument were i--, the loop would print the character with code i + 100 and then i: 105 is 'i', so it would print i5h4g3f2e1 (option A) and stop when i reached 0. Option B would need the decrement before printing, and an infinite loop (D) would need i never to reach 0.

Please log in or register to report this question.

7.

The two statements that can change the flow of control are :

Exam Year(s)

MH SET - 2023, SET Exam - 2023,

Answer: A

The keyed answer is break and continue.

break and continue are jump statements: their only effect is to transfer control. break leaves the innermost loop or switch immediately, and continue skips the rest of the current loop iteration and goes to the next one. They change the flow of control inside a structure that is already running.

if, switch, while and do-while are selection and iteration constructs: they define the structure of the flow, choosing which block runs or repeating it, rather than being statements that break the normal sequence. The key takes the question in this sense, so the pairs in A, B and C are not accepted.

Please log in or register to report this question.

8.

Which loop is guaranteed to execute at least once ?

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: C

The loop guaranteed to run at least once is do-while.

A do-while loop is exit-controlled: the body is written first and the condition is tested after it, so the body always executes once before the condition is checked for the first time.

for and while loops are entry-controlled. They test the condition before the first pass, so if it is false at the start the body never runs at all. Since do-while does guarantee one pass, 'None of these' is wrong.

Please log in or register to report this question.

9.

The following code 'for(;;)' represents an infinite loop. It can be terminated by

Exam Year(s)

Tripura Public Service Commission - 2019,

Answer: A

The key's answer is break.

The break statement terminates the innermost loop and passes control to the statement after it, so it is the way to end a for(;;) loop and carry on with the program.

exit(0) and abort() also stop the loop, but only by ending the whole program; they terminate the process, not the loop. The question bank this is taken from treats only break as terminating the loop itself, which is why 'All of the mentioned above' is not the key.

Please log in or register to report this question.

10.

Which loop structure would execute its statements atleast once even if the test condition fails for the first time itself ?

Exam Year(s)

UGC NET - 2012,

Answer: C

The do-while loop tests its condition at the end, after the body has been executed once, so its statements run at least once even if the test condition is false the first time. The for loop and the while loop test the condition before entering the body, so a condition that is false at the start gives no execution at all. The if-else is a selection statement and not a loop. The answer is do-while.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Control Instructions Questions and Answers || Control Instructions MCQ Questions and Answers || Control Instructions GK Questions and Answers || Control Instructions GK MCQ Questions || Control Instructions Multiple Choice Questions and Answers || Control Instructions GK || GK on Control Instructions || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming