+ 1
For Loop, I used a Do while to do the same, Help to understand a Difference
I used a Do while to replicate an excercise of For Loop, Is there a difference I have to consider for the future? or these two control structures are the same but with different sintax. The example is for ($a = 0; $a < 6; $a++) { echo "Value of a : ". $a . "<br />"; } ___________________________________ $i = 0; do { echo "Value of a: $i <br/>"; $i++; } while($i < 6); Thanks
2 odpowiedzi
+ 1
The FOR will loop while the value of your int is less than the given limit (6)
The DO WHILE will execute ONE time before it stars to look until the limit you've set or the user has.
More info here: https://www.quora.com/What-is-the-difference-between-do-while-and-for-loops-Which-is-best-for-programing#MoreAnswers
0
Both are different. If you want to see the difference, just replace "less than" operator with "greater than" operator in both loops.
Example: $a > 6