The for loop is simply a while loop with a bit more code added to it. The common tasks that are covered by a for loop are:
The for loop allows you to define these steps in one easy line of code. It may seem to have a strange form, so pay close attention to the syntax used!
Let us take the example from the while loop lesson and see how it could be done in a for loop. The basic structure of the for loop is as follows:
Notice how all the steps of the loop are taken care of in the for loop statement. Each step is separated by a semicolon: initiliaze counter, conditional statement, and the counter increment. A semicolon is needed because these are separate expressions. However, notice that a semicolon is not needed after the "increment counter" expression.
Here is the example of the brush prices done with a for loop .
Note For more detail please see Php Manual at http://www.php.net
While loop နဲ႔ for loop ဟာ အတူတူ ပါပဲ၊ ေရးပံု ေရးနည္း ေလးပဲ နည္းနည္း ကြာပါတယ္။
for ( initialize a counter; conditional statement; increment a counter) { do this code; }
for ($counter = 10; $counter <= 100; $counter += 10) { do this code; }
For loop မွာ for( ---------- ) ဆိုၿပီး ထိပ္မွာ code တစ္လိုင္း ပါပါတယ္။ ကြင္းစ "(" နဲ႔ ကြင္းပိတ္ ")" ၾကားမွာ semicolon ";" ခံၿပီး သံုးပိုင္း ပိုင္းထား ပါတယ္။ (xxx;yyy;zzz)
၄င္း ၃ ပိုင္းအနက္:- ၁။ ပထမ အပိုင္းက counter ကို နံပါတ္ ဘယ္ေလာက္ နဲ႔ စမယ္ ဆိုတာ ကို သတ္မွတ္ ေပးပါတယ္။ ၂။ ဒုတိယ အပိုင္းက conditional statement ျဖစ္ပါတယ္။ ၃။ တတိယ အပိုင္းက counter ကို အေရ အတြက္ ထပ္တိုးေပး တဲ့အပိုင္း ျဖစ္ပါတယ္။
၁၀ နဲ႔စပါ -- ၁၀၀ မေက်ာ္ မခ်င္း loop လုပ္ပါ --- မူလ ၁၀ မွာ ေနာက္ထပ္ ၁၀ ေပါင္းထည့္ပါ လို႔ အဓိပၸယ္ ရပါတယ္။
က်န္တဲ့ code ေတြ လုပ္ေဆာင္ပံု ကေတာ့ while loop မွာအတိုင္း ျဖစ္ပါတယ္။