Jump to content


Photo

while loop


  • Please log in to reply
5 replies to this topic

#1 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 13 June 2006 - 02:47 PM

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


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


// or do I do this


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

// Or are they identical??????????????



#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 13 June 2006 - 02:49 PM

Your first attempt is valid.

#3 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 13 June 2006 - 03:12 PM

Please disreguard my question, I was obviously out of my mind when I asked that...

FOCUS, man, FOCUS!

LOL


#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 13 June 2006 - 03:32 PM

There is two type of while loop do-while loop and while loop they are same apart from do-while is like this:
do {


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


#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 13 June 2006 - 03:42 PM

Esentually a while loop is different from a do while.

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

#6 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 13 June 2006 - 04:41 PM

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) View Post[/div][div class=\'quotemain\'][!--quotec--]
Esentually a while loop is different from a do while.

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users