+ 3
Can we use for loop always instead of while or do while loop ?
6 Answers
+ 3
Yes you could always use a for loop instead of while/do-while. Not very good programming standards though.
+ 2
okk
+ 2
You can use only for loops, but while/do while loops are much useful to read/write (and probably better implemented) in certain cases ^^
You can also ruse while/do while loops instead for loops, but in others circumstances, the for loop is better designed for :P
Anyway, using any loop will not make a lot of difference at end, and could be implemented in same way under the hood (in real machine code)... ;)
+ 1
no ...you cannot use for loop always .....you may the know the difference between them ....let me tell you 1 ..... do while loop code runs at least one time but in for loop condition is used before than code ......
+ 1
but its easy modify the initializer/condition to run for loop at least one time
0
for (;;) is an infinite loop. You just have to make sure that you use 'break' at some point to exit the loop, since it doesn't check on each iteration.