Jump to content

while loop


AV1611

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]

Link to comment
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.
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.