I am having trouble finding out what the purpose of this semicolon is at for (;
. My searches online have only brought irrelevant results. Can someone explain this please?
for (; $this->foo <=10; $this->foo++) {}
I am having trouble finding out what the purpose of this semicolon is at for (;
. My searches online have only brought irrelevant results. Can someone explain this please?
for (; $this->foo <=10; $this->foo++) {}
This basically skips the initializing of the iterator variable. Normally you'd type something like this:
for ($i = 0; $this->foo <= 10; $i++) {}
in your example however your object which is accessed by the $this
simply accumulates the foo by 1;
The first expression in a for loop is being executed at the beginnig of the loop, usually for initializing a variable.
In this for loop the expression is empty, so nothing is going to happen at the beginning.
For
loop can work fine with for(;;)
which is known as infinite loop.
It doesn't have any initialization part, no conditional checks and no post operation.
for(initialization, condition check, increment/decrement)
These are the 3 parts of for
loop