[GRLUG] What's Z + 1
    Michael Mol 
    mikemol at gmail.com
       
    Wed Oct 31 22:47:25 EDT 2007
    
    
  
On 10/31/07, Justin Denick <justin.denick at gmail.com> wrote:
> Depends on what you're counting with.
>
> I needed to loop over [A-Z] to make some anchors and stumbled across
> something interesting.
>
> for ($i="A"; $i < Z; $i++):
>   echo($i);
> endfor;
>
>  Gives ABCD{..}XY
>
> for ($i="A"; $i <= Z; $i++):
>    echo($i);
>  endfor;
>
> Gives ABCD{..}XYZAABB{..}
>
> So I'm using
> for ($i="A"; ($i <= Z and $i != "AA"); $i++):
>    echo($i);
>  endfor;
>
> This produces the desired results.
>
> From what I understand the default php behavior matched perl in that Z++ =
> "AA" not "]" as it would in C (so I 've read)
>
> Is there a better way to do this?
Had fun with this for a bit.  This is what I came up with:
for ( $i = "A"; strlen($i) < 2; ++$i )
        echo $i;
-- 
:wq
    
    
More information about the grlug
mailing list