PHP While Loop With Example

aimtocode

While loop

The while statement will execute a block of code as long as test expression is true.

If the test expression is true then the code block will be executed. After the code has executed the test expression will again be evaluated and the loop will continue until the test expression is found to be false.

Syntax:

while(condition)						
{
	code to be executed;
}

Example:



Result:


  Loop stopped at i =1 and num = 40



Read also:


aimtocode