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.

Kuber said:   1 decade ago
4th statement is wrong.
@Sundar:
you putted that condition inside loop. we can do same thing with while loop also. So i dont think statement 4 is true, its wrong.

Vanchi said:   1 decade ago
For the 4th statement do- while only correct because the other two are entry control loop statements. So it executes the condition at the end when the statement in the loop is get executed at least once.

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

Yash said:   1 decade ago
@ Girish & Khushi

If we write any statement after statement 3 that is not executed because the statement 3 executes infinitely.

This works like "while(1);" in C and while(true); in java.

Khushi said:   1 decade ago
How statement 3 is infinite loop????
for(i=0;i<5;i++);
this will terminate after 5 iterations...
and value of i would be 5 now...

Can anyone explain???

Girish nischel said:   1 decade ago
As per statement 3, i am convinced with the several explanations above! but when v are writing for(;;);...this means v r executing nothing infinetly! so in what case can the above statement is useful as an infinite loop??

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

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

printf("%d ", i);

}

Khush said:   1 decade ago
@Ranganath : its mentioned tht "for loop CAN be used..."

Ranganath M said:   1 decade ago
For 4th statement do_while loop only correct.

Ranganath M said:   1 decade ago
Here I can say that 4th statement is wrong, because it is not sure that a for loop can atleast be executed one time.

Have a look at the following :

int main()
{
int i;
for(i=0;i>5;i++) //at first time only condition fails
printf("hi");
}


Post your comments here:

Your comments will be displayed after verification.