Whats wrong with this code?

Questions about programming languages and debugging
Post Reply
User avatar
Broken Angel
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 432
Joined: 05 Jul 2010, 04:58
13
Contact:

Whats wrong with this code?

Post by Broken Angel »

http://code.suck-o.com/42381" onclick="window.open(this.href);return false;" onclick="window.open(this.href);return false;

What is wrong in this code pls??
God Blessed Me With Forgiveness And I Forgive You With My Revenge...!



-Broken Angel

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: Whats wrong with this code?

Post by ayu »

You are incrementing the $i variable outside of the loop, thus $i will always be less than $n, so the loop will go on forever.
"The best place to hide a tree, is in a forest"

User avatar
Broken Angel
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 432
Joined: 05 Jul 2010, 04:58
13
Contact:

Re: Whats wrong with this code?

Post by Broken Angel »

Ok i just put the

++$i inside the { } in the end as in like this

Code: Select all

{echo....
++$i
}

but the output comes with this error:
I
don't
know
how
this
works
but
we
will
still
do
it.

Notice: Undefined offset: 12 in C:\xampp\htdocs\simple_blog_1\while_do_practicla.php on line 10


Notice: Undefined offset: 13 in C:\xampp\htdocs\simple_blog_1\while_do_practicla.php on line 10


Notice: Undefined offset: 14 in C:\xampp\htdocs\simple_blog_1\while_do_practicla.php on line 10


and now this goes on for ever :-k #-o ](*,) ](*,) :? 8O [-X
God Blessed Me With Forgiveness And I Forgive You With My Revenge...!



-Broken Angel

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Re: Whats wrong with this code?

Post by ayu »

This works without any issues

Code: Select all

<?php
$foo=array("I","don't","know","how","this","works","but","we","will","still","do","it.");
$i=0;
$n=count($foo); //This stroes the number of values in the array
while ($i<$n){
        echo $foo[$i],"<br />";
++$i;
}

?>
"The best place to hide a tree, is in a forest"

Post Reply