Iteration through letter
7 answers - 454 bytes -

Hi,
just for fun I tried the following code:
<code>
for($letter = 'A'; $letter <= 'Z'; ++$letter) {
echo($letter . ' ');
}
</code>
What surprised me was the output, which looked like this:
A B C [] Y Z AA AB AC [] YY YZ
I don't have any idea how these letters get printed out, so I'd
appreciate any guesses or explanations.
thanks,
Norbert
No.1 | | 660 bytes |
| 
Thu, 2006-09-14 at 19:26 +0200, Norbert Wenzel wrote:
Hi,
just for fun I tried the following code:
<code>
for($letter = 'A'; $letter <= 'Z'; ++$letter) {
echo($letter . ' ');
}
</code>
What surprised me was the output, which looked like this:
A B C [] Y Z AA AB AC [] YY YZ
I don't have any idea how these letters get printed out, so I'd
appreciate any guesses or explanations.
Read the manual and search the archives, this was beaten to a bloody
pulp several months ago. (Hint: this DESN'T work like ascii in C).
Cheers,
Rob.
No.2 | | 917 bytes |
| 
Norbert Wenzel wrote:
Hi,
just for fun I tried the following code:
<code>
for($letter = 'A'; $letter <= 'Z'; ++$letter) {
echo($letter . ' ');
}
</code>
What surprised me was the output, which looked like this:
A B C [] Y Z AA AB AC [] YY YZ
I don't have any idea how these letters get printed out, so I'd
appreciate any guesses or explanations.
This was discussed a lot a couple months back (Rasmus answered it about
20 times). This is my rendition.
When you increment a string, you get:
'A' + 1 is 'B'
'Z' + 1 is 'AA'
Because of how string comparisons go, 'AA' is greater than 'Z' (strings
are compared letter by letter), so the loop won't terminate at 'Z', like
you'd expect.
jon
No.3 | | 814 bytes |
| 
Thursday 14 September 2006 12:26, Norbert Wenzel wrote:
Hi,
just for fun I tried the following code:
<code>
for($letter = 'A'; $letter <= 'Z'; ++$letter) {
echo($letter . ' ');
}
</code>
What surprised me was the output, which looked like this:
A B C [] Y Z AA AB AC [] YY YZ
I don't have any idea how these letters get printed out, so I'd
appreciate any guesses or explanations.
thanks,
Norbert
This topic was discussed at quite some length before, and Rasmus helped us all
understand it. The reason that happens is the next "letter" after Z is AZ,
which alphabetically is less than Z. You could change your statement to use
$letter < 'AZ'. I think that would work.
No.4 | | 826 bytes |
| 
Thursday 14 September 2006 12:41, Robert Cummings wrote:
Thu, 2006-09-14 at 19:26 +0200, Norbert Wenzel wrote:
Hi,
just for fun I tried the following code:
<code>
for($letter = 'A'; $letter <= 'Z'; ++$letter) {
echo($letter . ' ');
}
</code>
What surprised me was the output, which looked like this:
A B C [] Y Z AA AB AC [] YY YZ
I don't have any idea how these letters get printed out, so I'd
appreciate any guesses or explanations.
Read the manual and search the archives, this was beaten to a bloody
pulp several months ago. (Hint: this DESN'T work like ascii in C).
Cheers,
Rob.
I was typing up my response before yours came in looks like I made the
spoiler ;)
Later,
No.5 | | 879 bytes |
| 
Thu, 2006-09-14 at 12:51 -0500, Ray Hauge wrote:
Thursday 14 September 2006 12:41, Robert Cummings wrote:
Thu, 2006-09-14 at 19:26 +0200, Norbert Wenzel wrote:
Hi,
just for fun I tried the following code:
<code>
for($letter = 'A'; $letter <= 'Z'; ++$letter) {
echo($letter . ' ');
}
</code>
What surprised me was the output, which looked like this:
A B C [] Y Z AA AB AC [] YY YZ
I don't have any idea how these letters get printed out, so I'd
appreciate any guesses or explanations.
Read the manual and search the archives, this was beaten to a bloody
pulp several months ago. (Hint: this DESN'T work like ascii in C).
Cheers,
Rob.
I was typing up my response before yours came in looks like I made the
spoiler ;)
Doh! :)
No.6 | | 702 bytes |
| 
Norbert Wenzel wrote:
Hi,
just for fun I tried the following code:
<code>
for($letter = 'A'; $letter <= 'Z'; ++$letter) {
echo($letter . ' ');
}
</code>
What surprised me was the output, which looked like this:
A B C [] Y Z AA AB AC [] YY YZ
I don't have any idea how these letters get printed out, so I'd
appreciate any guesses or explanations.
thanks,
Norbert
Thanks for all your replies and sorry about asking a question answered
in the manual. I was too surprised of the result, so I didn't even think
I could find that topic in the manual. Sorry.
Norbert
No.7 | | 525 bytes |
| 
2006/9/14, Norbert Wenzel <mail (AT) brain4art (DOT) at>:
Hi,
just for fun I tried the following code:
<code>
for($letter = 'A'; $letter <= 'Z'; ++$letter) {
echo($letter . ' ');
}
</code>
What surprised me was the output, which looked like this:
A B C [] Y Z AA AB AC [] YY YZ
I don't have any idea how these letters get printed out, so I'd
appreciate any guesses or explanations.
thanks,
Norbert