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 3 of 5.

Pallavi said:   1 decade ago
The 4th statement is "CAN BE USED" which suggests in some cases not always. If the statement was always be used for executing the body at least once. Then the answer would be "do...while".

Arpit gupta said:   1 decade ago
Statement 4 is true in case of do while loop not in case of for loop. Let assume if condition is false initially then for loop never executed. So 4th statement is wrong for for loop.

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.

Sundar said:   1 decade ago
@Deepa

The following is the valid for loop.

int i=0;

for(;;)
{
printf("%d ", i++);

if(i == 10) break; // condition checking is done here.
}

Gautam said:   9 years ago
4th option is incorrect as:

for(i=5;i<=2;i++)
printf("%d",i+1);

This won't execute even once.

Anyone tell me, if the above program is false?

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???

Thiyagarajan said:   1 decade ago
"for loop can be used if we want statements in a loop get executed at least once. ".

How? Can you tell that the above statement is write please explain.

Jot said:   1 decade ago
If you want the statements inside the loop must execute at least once then you need do-while loop. I disagree somehow on the truth of Statement 4.

Raj said:   7 years ago
This statement "for loop can be used if we want statements in a loop get executed at least once" is True or False.

Please anyone give answer.

Pawan kumar saini said:   9 years ago
I think statement 3 is right.

int i=5;
for(;i<4;i++)
{
printf("%d",i);
}

It will not print at least one time.


Post your comments here:

Your comments will be displayed after verification.