Page 1 of 1

What's wrong?

Posted: Wed Nov 09, 2011 4:57 pm
by mikeashfield

Code: Select all

<?php
$counter=1;
while ($counter =< 20) {
echo $counter . '/n';
$counter++;
}
?>
Very elementary I know, but if anyone could help, that'd be great.

Re: What's wrong?

Posted: Wed Nov 09, 2011 5:15 pm
by Celauran
You have =< when you want <=
You have '/n' when you want "\n"

Re: What's wrong?

Posted: Wed Nov 09, 2011 5:16 pm
by mikeashfield
Really? Who would have thought they were any different. Thanks for the heads up anyway, works a charm now.

Re: What's wrong?

Posted: Wed Nov 09, 2011 8:04 pm
by twinedev
Some languages don't care if you do =< or <=, PHP does

Another way of doing it:

Code: Select all

for($counter=1;$counter<=20;$counter++) {
    echo $counter,"\n";
}