RE: [PHP] A to Z incremental

2004-04-23 Thread Ford, Mike [LSS]
On 22 April 2004 15:22, Paul wrote:

 Hi!
 Got this script:
 
 ?php
 for($i='A';$i='Z';$i++){  echo $i.' | ';  }
  
 
 The output is:
 A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P
  Q | R | S | T | U | V | W | X | Y | Z |
  AA | AB | AC |
  ...
   YX | YY | YZ |
 
 where is should display only letters from A to Z.
 Why is that?

Because 'Z'++ (if you see what I mean!) is 'AA'.

(So, at the end of the loop iteration which echoes 'Z', $i becomes 'AA',
which is 'Z', and as a result the loop continues on through all the values
you saw.  The loop terminates after 'YZ' is echoed, since at the end of that
iteration $i increments to 'ZA', which is not 'Z', and Bob's your uncle!)

One way of solving this is:

   for ($i='A'; $i!='AA'; $i++)

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] A to Z incremental

2004-04-23 Thread electroteque
use the chr($i) system

 -Original Message-
 From: Ford, Mike [LSS] [mailto:[EMAIL PROTECTED]
 Sent: Friday, April 23, 2004 9:31 PM
 To: 'Paul'; [EMAIL PROTECTED]
 Subject: RE: [PHP] A to Z incremental


 On 22 April 2004 15:22, Paul wrote:

  Hi!
  Got this script:
 
  ?php
  for($i='A';$i='Z';$i++){  echo $i.' | ';  }
  
 
  The output is:
  A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P
   Q | R | S | T | U | V | W | X | Y | Z |
   AA | AB | AC |
   ...
YX | YY | YZ |
 
  where is should display only letters from A to Z.
  Why is that?

 Because 'Z'++ (if you see what I mean!) is 'AA'.

 (So, at the end of the loop iteration which echoes 'Z', $i becomes 'AA',
 which is 'Z', and as a result the loop continues on through all
 the values
 you saw.  The loop terminates after 'YZ' is echoed, since at the
 end of that
 iteration $i increments to 'ZA', which is not 'Z', and Bob's your uncle!)

 One way of solving this is:

for ($i='A'; $i!='AA'; $i++)

 Cheers!

 Mike

 -
 Mike Ford,  Electronic Information Services Adviser,
 Learning Support Services, Learning  Information Services,
 JG125, James Graham Building, Leeds Metropolitan University,
 Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
 Email: [EMAIL PROTECTED]
 Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] A to Z incremental

2004-04-23 Thread Rob Ellis
On Fri, Apr 23, 2004 at 09:41:39PM +1000, electroteque wrote:
 use the chr($i) system

or range()...

  print implode(' | ', range('A', 'Z'));

- rob

 
  -Original Message-
  From: Ford, Mike [LSS] [mailto:[EMAIL PROTECTED]
  Sent: Friday, April 23, 2004 9:31 PM
  To: 'Paul'; [EMAIL PROTECTED]
  Subject: RE: [PHP] A to Z incremental
 
 
  On 22 April 2004 15:22, Paul wrote:
 
   Hi!
   Got this script:
  
   ?php
   for($i='A';$i='Z';$i++){  echo $i.' | ';  }
   
  
   The output is:
   A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P
Q | R | S | T | U | V | W | X | Y | Z |
AA | AB | AC |
...
 YX | YY | YZ |
  
   where is should display only letters from A to Z.
   Why is that?
 
  Because 'Z'++ (if you see what I mean!) is 'AA'.
 
  (So, at the end of the loop iteration which echoes 'Z', $i becomes 'AA',
  which is 'Z', and as a result the loop continues on through all
  the values
  you saw.  The loop terminates after 'YZ' is echoed, since at the
  end of that
  iteration $i increments to 'ZA', which is not 'Z', and Bob's your uncle!)
 
  One way of solving this is:
 
 for ($i='A'; $i!='AA'; $i++)
 
  Cheers!
 
  Mike
 
  -
  Mike Ford,  Electronic Information Services Adviser,
  Learning Support Services, Learning  Information Services,
  JG125, James Graham Building, Leeds Metropolitan University,
  Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
  Email: [EMAIL PROTECTED]
  Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] A to Z incremental

2004-04-22 Thread Paul
Hi!
Got this script:

?php
for($i='A';$i='Z';$i++){  echo $i.' | ';  }
?
  
The output is:
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V 
| W | X | Y | Z |
 AA | AB | AC |
 ...
  YX | YY | YZ |

where is should display only letters from A to Z.
Why is that?

-- 
Best regards,
 Paul  mailto:[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] A to Z incremental

2004-04-22 Thread Pablo Gosse
snip
 Hi!
 Got this script:
 
 ?php
 for($i='A';$i='Z';$i++){  echo $i.' | ';  }
 
 
 The output is:
 A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R
   | S | T | U | V | W | X | Y | Z |  AA | AB | AC |  ... YX | YY | YZ
 | 
 
 where is should display only letters from A to Z.
 Why is that?
 
/snip

Hi, Paul. Try this instead.

$x = 65;
for ($i=0; $i26; $i++)
{
echo chr($x);
$x++;
}

Set $x to 97 to get lowercase letters.

HTH.

Pablo.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] A to Z incremental

2004-04-22 Thread John W. Holmes
From: Paul [EMAIL PROTECTED]

 ?php
 for($i='A';$i='Z';$i++){  echo $i.' | ';  }
 ?

 The output is:
 A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S
| T | U | V | W | X | Y | Z |
  AA | AB | AC |
  ...
   YX | YY | YZ |

 where is should display only letters from A to Z.
 Why is that?

'A' is less than 'Z' when we're talking about strings. Same as '1000' is
less than '2' when compared as strings. Doesn't really answer why, but
that's just how it is. :)

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] A to Z incremental

2004-04-22 Thread Paul
Hello Pablo,

Thursday, April 22, 2004, 4:05:23 PM, you wrote:

 Hi!
 Got this script:
 
 ?php
 for($i='A';$i='Z';$i++){  echo $i.' | ';  }
 
 
 The output is:
 A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R
   | S | T | U | V | W | X | Y | Z |  AA | AB | AC |  ... YX | YY | YZ
 | 
 
 where is should display only letters from A to Z.
 Why is that?
 

PG Hi, Paul. Try this instead.
...


Thanks Pablo!
I know that but I was curios why that happens.


-- 
Best regards,
 Paulmailto:[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: Re[2]: [PHP] A to Z incremental

2004-04-22 Thread Pablo Gosse
Paul wrote:
 Hello Pablo,
 
 Thursday, April 22, 2004, 4:05:23 PM, you wrote:
 
 Hi!
 Got this script:
 
 ?php
 for($i='A';$i='Z';$i++){  echo $i.' | ';  }
 
 
 The output is:
 A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q |
   R | S | T | U | V | W | X | Y | Z |  AA | AB | AC |  ... YX | YY
 | YZ 
 
 
 where is should display only letters from A to Z.
 Why is that?
 
 
 Hi, Paul. Try this instead.
 ...
 
 
 Thanks Pablo!
 I know that but I was curios why that happens.
 
 
 --
 Best regards,
  Paulmailto:[EMAIL PROTECTED]

Hi Paul.

Since you're dealing with a string, A is less than AA which will be less
than Z.  It's stopping at YZ because if it were to increment once more,
it would be ZZ, which (again, because this is a string) is greater than
Z so thus the loop exits.

HTH.

Cheers,
Pablo

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php