HOBALL 筆記簿

July 24, 2009

For-loop with two counting variables

Filed under: PHP — Tags: , — hoball @ 2:38 pm

Perma Link: http://stackoverflow.com/questions/1172553/php-for-loop-with-2-variables/1172565#1172565

for ($i=0, $k=10; $i<=10 ; $i++, $k--) {
    echo "Var " . $i . " is " . $k . "<br>";
}

Gumbo, Author of this code snippet:
The two variables $i and $k are initialized with 0 and 10 respectively. 
At the end of each each loop $i will be incremented by one ($i++) and $k decremented by one ($k—).
So $i will have the values 0, 1, …, 10 and $k the values 10, 9, …, 0.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: