For Loop In Php Programming Languages. This tutorial is for “For Loop”. Now syntax of For Loop is bit complicated. Also,its structure is slightly different. If we make blogs related to For loop you must observe that its similar to While Loop and Do While Loop. However, in For Loop what we are doing is we use three expressions within this brackets.These three expressions are ,firstly to initialize the variable then control the loop by giving a definite condition to the variable and lastly increment the initialized value of variable.
Code for For loop (Screenshot1):-
Screenshot1 |
Output (Screenshot2):-
Screenshot2 |
In this example, I am firstly declaring variable “count” in For Loop,secondly evaluate whether condition is true or false i.e.count is greater than or equal to ten and lastly increment the value of count.In For Loop,”;” sign between these expressions is must.Second expression will only get executed after execution of first expression and third expression will only get executed after execution of second expression whenever any For Loop is called for the first time in program.But from second time onward it will only execute second and third expressions,since the initialization of variable is done while calling the For Loop for the first time.
Html tags should be in single inverted commas at echo function of php programming languages.
Code for For loop (Screenshot3):-
Screenshot3 |
Output (Screenshot4):-
Screenshot4 |
In this example, we are counting from 10 to 1 by decremented the value of variables.So, this is basic For Loop in php.
No comments:
Post a Comment
Thanks For Comment Will get you Soon..