Difference between 'Loop' & 'While' -
[D]ry[D]esert - 08.08.2013
Hello there!
As the topic said, I really wanna know what the different between 'Loop' & 'While'
I've read samp wiki and still i didnt get it..
what 'while' can do and 'loop' cant ?
As i understand, while have the same function of loop, but some people told me
NO
I will be much thankful if someone explained me.
Re: Difference between 'Loop' & 'While' -
Black Wolf - 08.08.2013
First of all While is a loop.
Re: Difference between 'Loop' & 'While' -
[D]ry[D]esert - 08.08.2013
Quote:
Originally Posted by Black Wolf
First of all While is a loop.
|
Ah, Every While is a loop, What about 'Every loop is a while' ?\
I've notice that people use while in reading lines from file and load it..
So i'll be able to use for(....) instead using while, right ?
Re: Difference between 'Loop' & 'While' -
Vince - 08.08.2013
There is no such thing as a 'loop' keyword in Pawn.
for is used when you know how many iterations you want to do;
while is used when you don't know.
While loops are typically used for reading data from a resource, such as files or SQL, since these resources can return an arbitrary amount of data.
Re: Difference between 'Loop' & 'While' -
[D]ry[D]esert - 08.08.2013
Quote:
Originally Posted by Vince
There is no such thing as a 'loop' keyword in Pawn.
for is used when you know how many iterations you want to do; while is used when you don't know.
While loops are typically used for reading data from a resource, such as files or SQL, since these resources can return an arbitrary amount of data.
|
Thanks for sharing these
Valuable information.
Much appreciated.
Re: Difference between 'Loop' & 'While' -
[D]ry[D]esert - 09.08.2013
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.