#1

Could someone tell me where it is recommended to use "do"?
I saw this in sscanf and did not understand perfectly what he does.
pawn Код:
do
Reply
#2

https://sampwiki.blast.hk/wiki/While#do
Reply
#3

do is used in a while loop.

pawn Код:
do
{
    this();
}
while(this is true)
Edit: This forum doesn't give the warning if someone has posted meanwhile?
Reply
#4

I may have my terminology off here, but a do while loop is a post test loop, whereas a while loop is a pretest loop. That being, a do while loop will always execute at least once and then check the condition, whereas a while loop checks the condition then performs its tasks.
Reply
#5

An example of its use is the code to get a random player:
pawn Код:
new
    playerid;

do
{
    playerid = random(MAX_PLAYERS);
}
while(!IsPlayerConnected(playerid));
The value of "playerid" is set to a random value between 0 and 499. If the player with that ID (the random value) isn't connected, do it again. Do this, if it didn't work, do it again, if it didn't work, do it once again; that's how it works. However, I suggest you to not use that code, because that could freeze your server if there are now players connected.
Reply
#6

Everyone helped me to understand, I now know when and how to use, grateful.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)