Foreach skipping, switch cases. - 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)
+--- Thread: Foreach skipping, switch cases. (
/showthread.php?tid=573868)
Foreach skipping, switch cases. -
iReacheR - 11.05.2015
Umm...I was working on one of my scripts and I have to leave now, so, I was working on a problem where I want the foreach loop to go only once in one of the cases inside the switch. For example,
pawn Код:
foreach(new i : Player)
{
switch(whatever_var)
{
case 1:
{
//does whatever
//happens fully, like loops normally as foreach does.
}
case 2:
{
//does whatever
//occurs once, foreach does not loop through this case more than once <== That is the question, how to make that possible
}
}
}
So, yeah, I might as well figure it out when I come back but until then if someone can help it will be appreciated.
Re: Foreach skipping, switch cases. -
Nicker - 11.05.2015
You could do something like this:
pawn Код:
new checked = 0;
foreach(new i : Player)
{
switch(whatever_var)
{
case 1:
{
//does whatever
//happens fully, like loops normally as foreach does.
}
case 2:
{
if(checked == 0)
{
checked = 1;
//does whatever
//occurs once, foreach does not loop through this case more than once <== That is the question, how to make that possible
}
}
}
}
Sorry about the indentation, the forum messes it up.