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. |
Discussion:
48 comments Page 4 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".
Akash said:
1 decade ago
How is for loop slower than while loop?
Pradnya solke said:
1 decade ago
Only do...while loop can be used to execute statement atleast once.
Niraj said:
1 decade ago
If we want to execute a statement at least once, whatever the condition is true or false in this case we should use do-while loop instead of for loop. In do-while loop first statement is executed then condition is checked. While in FOR loop first condition is checked then statement is executed.
Harish said:
10 years ago
@Akash.
Both while and for loop are looks some what same and only difference is for loop looks simple than while, because all expressions are stated in a single for loop, where user can understand easily by looking for.
Both while and for loop are looks some what same and only difference is for loop looks simple than while, because all expressions are stated in a single for loop, where user can understand easily by looking for.
Sandhya said:
10 years ago
For(;;); here is semicolon is present after for then how it became a infinite loop.
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?
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?
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.
int i=5;
for(;i<4;i++)
{
printf("%d",i);
}
It will not print at least one time.
Sai lakshmi said:
9 years ago
How for loop is used to execute statements atleast once?
Abhilash said:
8 years ago
How come statement 3 be true?
We cannot put a semicolon after for bracket.
We cannot put a semicolon after for bracket.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers