continue and return 0 and return 1 and break work?
#1

Well i have question is continue and return 0; work same?
Код:
UnoccupiedVehicle(vehicleid)
{
  foreach(Player, i)
  {
      if(IsPlayerInVehicle(i,vehicleid)) return 0;
  }
  return 1;
}
Like this i tried that

Код:
UnoccupiedVehicle(vehicleid)
{
  foreach(Player, i)
  {
      if(IsPlayerInVehicle(i,vehicleid)) continue;
  }
  return 1;
}
look like both function work same?

I know continue skip that thing and move to code at top where it start for next iteration.
and break can break the loop and don't stop execute data after that break.

But kindly difference between those.
return 1 between break?
and
return 0 between continue?

what is difference?
Reply
#2

You should use the one with return.

Break will abruptly exit the loop. Continue will ignore the rest of the current iteration and move on to the the next one.
Reply
#3

Код:
UnoccupiedVehicle(vehicleid)
{
  foreach(Player, i)
  {
      if(IsPlayerInVehicle(i,vehicleid)) continue;
  }
  return 1;
}
Why this code didn't skip my id when i was in vehicle?

using return 0;

its skipping my id why?
Reply
#4

Using continue in a loop will skip the code under the keyword and go back to the start of the loop. Returning a value in a loop will break the loop, exit the function and return a value.

Quote:
Originally Posted by MBilal
Посмотреть сообщение
Код:
UnoccupiedVehicle(vehicleid)
{
  foreach(Player, i)
  {
      if(IsPlayerInVehicle(i,vehicleid)) continue;
  }
  return 1;
}
Why this code didn't skip my id when i was in vehicle?

using return 0;

its skipping my id why?
Because you aren't inside the specified vehicle ID, most likely.
Reply
#5

Quote:
Originally Posted by KevinReinke
Посмотреть сообщение
Using continue in a loop will skip the code under the keyword and go back to the start of the loop. Returning a value in a loop will break the loop, exit the function and return a value.



Because you aren't inside the specified vehicle ID, most likely.
I was inside vehicle i tested my self.

the code with return 0 work.
but the code with continue not work.

I want to know why continue not working and return 0 working?
Reply
#6

You're supposed to return 0/false when you detect someone inside the vehicle. Continue is starting a new iteration rather than stopping the current one, which is leading the function to ultimately return 1.
Reply
#7

Quote:
Originally Posted by MBilal
Посмотреть сообщение
I was inside vehicle i tested my self.

the code with return 0 work.
but the code with continue not work.

I want to know why continue not working and return 0 working?
Try using this:

UnoccupiedVehicle(GetPlayerVehicleID(playerid));
Reply
#8

Quote:
Originally Posted by zPain
Посмотреть сообщение
You're supposed to return 0/false when you detect someone inside the vehicle. Continue is making the loop start a new iteration rather than stopping the current one, which is leading the function to ultimately return 1.
Thank all
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)