Jump to content

Archived

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

AV1611

while loop

Recommended Posts

Is this valid syntax, or do I need to add "DO {"

[code]

while ($i <= 998)
        {
                 // Do some stuff here
        }


// or do I do this


while ($i <= 998)
        {
            do{
                        //Do some stuff here
                        }
        }

// Or are they identical??????????????
[/code]

Share this post


Link to post
Share on other sites
Your first attempt is valid.

Share this post


Link to post
Share on other sites
Please disreguard my question, I was obviously out of my mind when I asked that...

FOCUS, man, FOCUS!

LOL

Share this post


Link to post
Share on other sites
There is two type of while loop do-while loop and while loop they are same apart from do-while is like this:
[code]do {


}
while($i <= 998);[/code]
I prefer to use just while whithout the do bit.

Share this post


Link to post
Share on other sites
Esentually a [i]while[/i] loop is different from a [i]do while[/i].

With a while() your expression is evaluated before each iteration of the loop, do while evaluates the expressions after each iteration.

Share this post


Link to post
Share on other sites
Thanks you... that mean the while exit is determined by the clause, and the do is determined by some other criteria...

that is very usefull information... I always wondered if there was a difference...

Thank

[!--quoteo(post=383325:date=Jun 13 2006, 11:42 AM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 13 2006, 11:42 AM) [snapback]383325[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Esentually a [i]while[/i] loop is different from a [i]do while[/i].

With a while() your expression is evaluated before each iteration of the loop, do while evaluates the expressions after each iteration.
[/quote]

Share this post


Link to post
Share on other sites

×

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.