+ 3

Can we use for loop always instead of while or do while loop ?

14th Jun 2017, 2:58 PM
Master Gaurav
6 Respuestas
+ 3
Yes you could always use a for loop instead of while/do-while. Not very good programming standards though.
14th Jun 2017, 3:57 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
okk
14th Jun 2017, 4:25 PM
Master Gaurav
+ 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)... ;)
14th Jun 2017, 4:55 PM
visph
visph - avatar
+ 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 ......
14th Jun 2017, 3:05 PM
#Happy@777
#Happy@777 - avatar
+ 1
but its easy modify the initializer/condition to run for loop at least one time
14th Jun 2017, 3:31 PM
Andrea Simone Costa
Andrea Simone Costa - avatar
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.
15th Jun 2017, 3:15 AM
Zeke Williams
Zeke Williams - avatar