The three types of loops available in C language are i. for Which loops do not operate without testing the condition even once ?
ii. while
iii. do-while
i, ii
Read the question as "which loops test the condition before doing anything?" — and the answer is the two pre-test loops, for and while, option 2.
| Loop | Test position | Minimum executions of the body |
|---|---|---|
| for | Before the body | 0 |
| while | Before the body | 0 |
| do-while | After the body | 1 |
What this means in practice. Write
for (i = 0; i < n; i++) { ... }
with n equal to zero, and the body never runs at all — the condition is evaluated once, found false, and control passes on. The same is true of while (n) with n zero. But
do { ... } while (n);
executes its body first and only then discovers that n is zero, so the body has already run once.
Why the distinction matters, not just for exams. It decides which loop is correct for a given task.
Use a pre-test loop whenever "no iterations" is a legitimate outcome — processing a list that might be empty, reading a file that might contain nothing, retrying an operation that might already have succeeded. Using do-while there would process an element that does not exist.
Use do-while whenever the body must run at least once before the test can even be meaningful — the classic case being a menu, which must be displayed before the user's choice can be read and checked. Writing that as a while loop forces an artificial initialisation of the variable being tested.
A note on for against while. They differ only in convenience, not in behaviour: for gathers initialisation, test and update into one header, which suits counted loops, while while suits loops governed by a condition that is updated somewhere in the body. Any for can be rewritten as a while and the reverse, and both test first — which is why both belong in the answer.
Remember also that do-while requires a terminating semicolon after its condition; omitting it is a common compile error, and it is the only loop form in C that needs one.
Hence, the loops that test the condition first are for and while.
The function "isalnum( )" returns a non-zero value if the character is alphanumeric and zero otherwise. What is header file to be used in the main program ?
To read a integer variable, find the correct format given below :
Int m;
Find the correct list, which is the reverse (at all levels) of the given list :
[[4, 7, 8], 2, 9, [19, 6], 20, 3]
(i) 3, 20
(ii) 9, 2
(iii) [6, 19]
(iv) [8, 7, 4]
Which of the following is not an infinite loop ?
(A) int i = 1;
while (1)
{
i++ ;
}
(B) for ( ; ; ) ;
(C) int t = 0, f ;
while (t)
{
f = 1;
}
(D) int y, x = 0 ;
do
{
y = x;
}
while (x == 0);
Match the following :
| List – I | List – II |
| a. associativity | i. memory storage |
| b. # define | ii. if-then-else |
| c. auto | iii. operators with equal precedence |
| d. conditional operator | iv. define operator |
Codes :
Assertion (A) : 'C' uses many data types such as integers (short and long) and float etc.
Reason (R) : Conversion specifier used for short unsigned integer is % lu.
Which bitwise operator is suitable for turning off a particular bit in a number ?
Which storage class is used for the variables that are often required in a program ?
Which is not a proper way of array declaration ?
Exponentiation operation in C is carried out as
Which of the following is NOT a state function or state variable in a thermodynamic system?