PHP for loop
A for loop is a control statement using which the programmer can give instructions to the computer to execute a set of statement repeatedly as long as specified condition is satisfied. It is required to specify how many times a set of statements have to be executed it is also called counter controlled loop.Syntax:-
for(exp 1; exp 2; exp 3)
for is a keyword followed by three expression enclosed within parentheses.Here:-
The first expression : exp 1 contains initialization statements.
The second expression:- exp 2 contains limit – test expression.
The third expression :- exp 3 contains updating expression.
When for loop is used
The for loop is always used when we know initial value final value and updating value . The updating value can be constantly incremented or decremented.
W.A.P to print 1 to 5 using for loop.
for($i = 1; $i <=5 ; $i++)
1 2 3 4 5