C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - Point Out Correct Statements (Q.No. 7)
7.
Which of the following sentences are correct about a for loop in a C program?
1: for loop works faster than a while loop.
2: All things that can be done using a for loop can also be done using a while loop.
3: for(;;); implements an infinite loop.
4: for loop can be used if we want statements in a loop get executed at least once.
1
1, 2
2, 3
2, 3, 4
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
48 comments Page 4 of 5.

Abc said:   1 decade ago
main ()
{
int i=2;
printf("%d ", i);

for(;i<=1;)
{
printf("%d ", i++);
}

printf("%d ", i);

}

Naive_coder said:   2 decades ago
For loop is ultimately broken down to same machine code as a while loop doing same function. So their speed might be same.

Sathiya Baskar said:   6 years ago
for(;;);
will not execute..

if for(;;)--->> it will execute infinite times.

Am I right? Please tell me.
(4)

Krishna said:   1 decade ago
do while is used to print statements at least once.

Is, for loop is used to print statements at least once.

Srinivas16 said:   1 decade ago
for loop is not end with semicolon (;)

for(i=0;i<n;i++)
{

}

Then why statement 3 is correct ?

Piyush jain said:   1 decade ago
Option 4 is correct.

Watch carefully that its written "can be used" in the question.

Jit said:   1 decade ago
Option C would be the answer. There is a conflict between do-while & for. Reported.

Nidhi said:   6 years ago
Statement 4 is wrong. "do while" loop is used for at least one execution not for loop.
(4)

Sandhya said:   10 years ago
For(;;); here is semicolon is present after for then how it became a infinite loop.

Abhilash said:   8 years ago
How come statement 3 be true?

We cannot put a semicolon after for bracket.


Post your comments here:

Your comments will be displayed after verification.