#1

hello guys i have question, is possible to use "break" for returning values from loop and breaking down a loop?
Example:
Код:
stock GetVehicleIDFromSQL(sqlid)
{
	for(new i = 1; i <= MAX_VEHICLES; i++)
	{
	    if(IsValidVehicle(i))
	    {
			if(sqlid == AVDB[i][CSQLID])
 			{
   				//return i;
   				break i;
  			}
   		}
	}
   	return INVALID_VEHICLE_ID;
}
Reply
#2

break is simply the function that terminates a loop. If you want the loop to stop and return a value, you must use 'return'.

break - Stops a loop completely.
return - Stops a loop completely, but the function overall will return the given value.

https://sampwiki.blast.hk/wiki/Control_Structures#break
https://sampwiki.blast.hk/wiki/Control_Structures#return
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)