Page 1 of 1

Interesting For Loop =))

Posted: Fri Sep 02, 2011 8:09 am
by tang3li2
hey guys, i have this intriguing code that really amazed me, anyway i'm just a months old in learning php and probably you all guys can understand my post heheheh,
here's the code

Code: Select all

$x=0; 
$n=0;
for(;$x+=11==(++$n.$n)%22,$n<100;)
   echo"N=$n,A=$x";
actually i've been trying to figure it out, i also break it down, using the basic loop, and put inside the loop "echo $x+=2 == (++$n) % 2", because in my understanding if the condition become true, it will put a new value in var $x, but it doesn't seems right, it continue printing 1-99,
can someone help me through out of this :D,
Thank you so much in advance =)

Re: Interesting For Loop =))

Posted: Fri Sep 02, 2011 9:11 am
by genix2011
Hi,

hmm.... seems like it increments $n every loop but the $x irregularly :-D

if the condition is true it will add 1 to $x, not reset it, it only increases it (+=).
Condition example: (if $n=3, it will check if the rest of 33 divided by 22 is 11)

Greets.

Re: Interesting For Loop =))

Posted: Fri Sep 02, 2011 10:54 am
by tang3li2
thank you so much sir :D