+ 3
still don't know the difference btn the for loop and the while loop.
6 Answers
+ 2
Almost the same. With 'for-loop' you know beforehand how many times it will iterate. For 'while-loop' it will loop until a condition is no longer met.
+ 1
thank you pals but I still need more clarifications.
0
it's your choice which to choose, if you know before hand how many times the loop must run, then use for loop.
0
In 'for loop' each iteration is done after the body is completed. In 'while loop' you can do iteration anywhere in the body of loop.
0
While loop is basically a for loop with only the condition statement. The initialization statement is given before the while loop and the increment or decrement statement is given inside the while loop.
0
Lets say your program flips a coin until you get heads. You don't know how many flips it will take, so you can't use a for loop, instead use the while loop and say while (tails) {flip again} ;