New course! Every coder should learn Generative AI!
Try a free lesson+ 4
+ 3
The for loop encapsulates the loop variable in a more compact syntax
+ 3
Use the search bar before posting in the Q&A forum because what you want to ask might have already been asked and answered. This will prevent adding to duplicates.
+ 1
For loops
0
Sometimes while loop is useful with some php functions, for example:
while (! feof($file)) {
// read the file
}
But when we use counter variable(s) the for loop is more convenient.
0
The "for" loop used only when we already knew the number of iterations.
The "while" loop used only when the number of iteration are not exactly known.