Loop Question - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Loop Question (
/showthread.php?tid=271554)
Loop Question -
TheArcher - 24.07.2011
If i have this Loop:
pawn Код:
for (new a = 0; a < 3; a++)
{
if (a == 1) continue;
printf("a = %d", a);
}
a is equal to 1 and it will be skiped.
That code can be equal to:
pawn Код:
for (new a = 0; a < 3; a++)
{
if (a == 1) return 0;
printf("a = %d", a);
}
Or i'm a bit confused?
Re: Loop Question -
Vince - 24.07.2011
No, continue just skips 1 iteration of the loop. Return stops the loop and aborts the function that it is in completely. Then you also have break, which breaks out of the loop prematurely and then goes on with the first code after the loop.
Re: Loop Question -
[HiC]TheKiller - 24.07.2011
Well, if you use return, it's the same as using break, it will break the loop.
pawn Код:
for (new a = 0; a < 3; a++)
{
if (a == 1) return 0; // Will be called first
printf("a = %d", a); // Won't be called
}
Re: Loop Question -
TheArcher - 24.07.2011
Quote:
Originally Posted by [HiC]TheKiller
Well, if you use return, it's the same as using break, it will break the loop.
pawn Код:
for (new a = 0; a < 3; a++) { if (a == 1) return 0; // Will be called first printf("a = %d", a); // Won't be called }
|
Vince said break is same as return 0 but also goes to first line of the loop.
Re: Loop Question -
[HiC]TheKiller - 24.07.2011
Quote:
Originally Posted by Anthony_prince
Vince said break is same as return 0 but also goes to first line of the loop.
|
Nah, he said that it goes to the first line after the loop
pawn Код:
for (new a = 0; a < 3; a++)
{
if (a == 1) break; //called
printf("a = %d", a);
}
//Will be called next
for (new a = 0; a < 3; a++)
{
if (a == 1) return 0; //called
printf("a = %d", a);
}
//Won't be called at all as the callback / function has been given a return value.
Re: Loop Question -
TheArcher - 24.07.2011
Oh thanks for helping.