Correct loop to use here?
#6

Always lay a simple foreach loop, when you reach your desired result (or exact opposite of it in some cases) break or return, that way your control structures are simple and you run into infinite loops less (which is a bane to most of the coders)
Here's an example
PHP код:
GenerateUniqueNum()
{
new 
generatednum=random(10);
 foreach(new 
Players)
 {
  if(
Number[i]==generatednum)
  {
   return 
GenerateUniqueNum();
  }
 }
 return 
generatednum;

Reply


Messages In This Thread
Correct loop to use here? - by Dokins - 12.06.2016, 13:33
Re: Correct loop to use here? - by Vince - 12.06.2016, 15:23
Re: Correct loop to use here? - by martanius - 12.06.2016, 15:49
Re: Correct loop to use here? - by lolumadd_ - 12.06.2016, 15:53
Re: Correct loop to use here? - by AbyssMorgan - 12.06.2016, 16:11
Re: Correct loop to use here? - by PrO.GameR - 12.06.2016, 16:15

Forum Jump:


Users browsing this thread: 1 Guest(s)