Quote:
Originally Posted by ******
Actually, the ONLY difference between "for" and "while" is variable scope and increment time:
pawn Код:
new i = 0; while (i != 10) { continue; ++i; } // i can be used here, but the loop will run forever.
pawn Код:
for (new i = 0; i != 10; ++i) { continue; } // i can't be used here, and the loop will end.
A perfect replication of the for loop above using while would look like:
pawn Код:
{ // Restrict the scope. new i = 0; while (i != 10) { goto _continue; _continue: ++i; } } // i can't be used here, and the loop will end.
You could also write the while loop using for:
pawn Код:
new i = 0; for ( ; i != 10; ) { continue; ++i; } // i can be used here, but the loop will run forever.
And because no one else has mentioned it:
Is always run at least once because the code comes before the check.
|
Wow, Thanks, That was very useful.
You've mentioned 'Forever loop (Not ended loop)', It's going to slow down the script, right ?
What what caused 'While' to be forever loop is 'Continue', right ?
Thanks again.