Jump to content

the one and only mysterious for loop


westonlea7

Recommended Posts

so, tell me why does the following script

 

 

 

<?php
$meh = 1;
print "key" . $meh . "=\$keys[" . $meh . "]";
?>

 

 

 

give the following result,

 

 

 

key1=$keys[1]

 

 

 

yet the for loop with the exact same code in the center

 

<?php
for ( $counter = 0; $counter > 5; $counter++){
print "key" . $counter . "=\$keys[" . $counter . "]";
}
?>

 

doesn't give anything when viewed in my browser?

 

???

Link to comment
https://forums.phpfreaks.com/topic/98688-the-one-and-only-mysterious-for-loop/
Share on other sites

because your for loop is hosed. it says "while $counter > 5" but $counter starts at 0 (which is NOT greater than 5), so the loop is exited.

 

for ( $counter = 0; $counter > 5; $counter++){

 

should be something more like:

 

for ( $counter = 0; $counter < 5; $counter++){

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.