0
what is the deference between for,while and do while loop
6 Réponses
+ 7
For and while loops are equivalent (though they have a different synthax), but you should generally use a for loop when you know how many times you will loop, and a while loop otherwise.
With a do while loop, you are garanteed to loop at least once as the condition is checked at the end of the loop rather than at the beginning like in a for or while loop.
+ 6
Do while works at least once.
" While" loop works only if the condition of it is true.
+ 3
while loop means like: "while this is happening, do this "
for loops means: "for this to happen, do this "
do while loop means:"do this, while this is happening "
i hope that kinda helps :)
+ 1
do while loop will run once even if the condition is false but in case of for & while loop condition should be true to run the loop.
for loop is used when you know the number of times the loop will run & while is used when you don't know how many times the loop will run
0
tnx
0
For is the easy way
And while is same but it checks before run
Do while is opposite