Re: A very strange loop!
| From: | Fredrik Thunberg | Date: | Mon, 09 Jul 2007 08:13:18 +0000 |
| Subject: | Re: A very strange loop! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-258482@lists.php.net to get a copy of this message | ||
For exactly the same reason as
for( $i = 0; $i < 10; $i++)
produces 0-9
It loops whule $i is lesser than 'Z'
When $i becomes 'Z' it stops and doesn't echo
But i guess you're having trouble with (note the '<='):
for ($i = 'A'; $i <= 'Z'; $i++)
{
echo $i . ' ';} This might produce a "wierd" result. This is because when $i is 'Z' and $i++ is run $i become 'AA' And: 'AA' < 'Z' So it loops until $i becomse 'ZA'. Xell Zhang skrev:
Hello all, I met a very strange problem today. Take a look at the codes below: for ($i = 'A'; $i < 'Z'; $i++) { echo $i . ' '; } If you think the output is A-Z, please run it on your server and try. Who can tell me why the result is not A-Z?-- /Thunis "This must be Thursday," said Arthur musing to himself, sinking low over his beer, "I never could get the hang of Thursdays." --The Hitchikers Guide to the Galaxy