yes... as the previous answerers said... but
there are reasons to use for instead of while!
first is remembering that this is a finite loop (aid to the programmer)
second is for can be optimized to use registers for the variable 'i', depending on what is in the loop, this can change the behavior form chunk chunk chunk to whizzzzzz.
third, the c language for statement can do a lot more than the normal (set;test;increment)... it's very cool and can easily be used instead of while.... even if you aren't incrementing by a number!
2006-11-28 05:13:40
·
answer #1
·
answered by jake cigar™ is retired 7
·
0⤊
0⤋
Yes but a for loop runs for a finite number of times whilst a while loop runs for an infinite number of times - often relying on an event to stop it
2006-11-28 04:15:29
·
answer #2
·
answered by cool_clearwater 6
·
0⤊
1⤋
No difference4. They both use counters.
Only differnce is, you might forget the counter in a while loop, since it isnt required.
The For loop requires the counter to be defined when it is declared, and wont compile otherwise, so your less apt to make an endless loop.
2006-11-28 04:21:01
·
answer #3
·
answered by schill289 1
·
0⤊
1⤋
Yes, but then it will be called a for while loop... X
2006-11-28 04:13:41
·
answer #4
·
answered by xerocs 5
·
0⤊
1⤋
yes you can, but if you'll need to create a counter variable and use that in the while statement
2006-11-28 04:13:24
·
answer #5
·
answered by rchlbsxy2 5
·
0⤊
2⤋
ya u can but the thing is that you have to give the increment/decrement operation at the ending stage of the while means........
for(i=0; i<50; i++)
{..........
........
.......}
instead you have to do is to.......
while(i<50)
{..........
.........
.........
i=i+1;
}
something like that.....
2006-11-28 04:32:19
·
answer #6
·
answered by keval_jp 1
·
1⤊
0⤋