PHP for loop
PHP for loop
Information :-
1] The loop is the most complex loop in PHP and is used when the user knows how often the block should be executed.
2] A for loop consists of an initialization statement, a test statement, and an update statement (an increment or decrement statement).
3] Loops for PHP can be used to iterate over a series of scheduled code.
4] If the number of iterations is known you should use it, otherwise use a loop.
5] This means that you will use a loop when you already know how many times you want to run a piece of code.
Syntax :-
for (initialization; condition; increment/decrement)
{
// enter code and executed
}
syntax explanation :-
initialization
:- - This part is executed once before the loop starts. It often used to initialize variables.
initialization
:- condition:-
- The condition that is evaluated before each iteration of the loop. If the condition evaluates to true, the loop continues; If it evaluates to false, the loop ends.
- increment/decrement :- This is done after each iteration of the loop. It is usually used to increase or decrease a number.
Flowchart
PHP for loop
Example :-
Q 1. show all number 20 to 50.
PHP for loop
Output :-
Q.2 Show all number Between 100 to 50 descending order.
PHP for loop
Example :-
PHP for loop
Output :-
Related Post :-
Post a Comment