Jump to content

Difference Between Loops


suttercain

Recommended Posts

Hi Everyone,

 

I have been studying PHP for about 6 weeks and am self educating. The one thing I cannot grasp is the specific difference.

 

Tell me if I have this right:

 

for - This is a basic loop that once executed will go through until a certain expression is met.

while - the same thing as the for loop but with just a different syntax

do while - same as while but will execute at least once even if an expression is not met.

foreach - used on arrays

 

 

Is there anything I am missing, wrong on or can someone do a basic explanation. I have looked in book and on sites but just want a basic rundown.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/42189-difference-between-loops/
Share on other sites

Pretty much, but a while loop is not the "same thing" as a for loop with different syntax. It is a much more complex construct. All you need to know about php can be found in the manual:

 

for: http://us3.php.net/manual/en/control-structures.for.php

while: http://us3.php.net/manual/en/control-structures.while.php

do while: http://us3.php.net/manual/en/control-structures.do.while.php

foreach: http://us3.php.net/manual/en/control-structures.foreach.php

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.