SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Scripting Help (https://forum.sa-mp.com/forumdisplay.php?f=12)
-   -   foreach help (https://forum.sa-mp.com/showthread.php?t=672628)

Bect 21/02/2020 08:01 PM

foreach help
 
Code:

for (new ax = 0; ax < 3; ax ++) { DestroyVehicle(a[ax]); }
How can I convert that to foreach without Iterator_Add...

SiaReyes 22/02/2020 02:51 AM

Re: foreach help
 
Code:

foreach (new ax : Range(0, 4)) // 0-2
{
 DestroyVehicle(a[ax]);
}


Robson04 23/02/2020 09:36 AM

Re: foreach help
 
Quote:

Originally Posted by SiaReyes (Post 4132172)
Code:

foreach (new ax : Range(0, 4)) // 0-3
{
 DestroyVehicle(a[ax]);
}


This loop is useless. Foreach is a advanced loop using iter. If your system does not need to have an iterator continent, use the default loop.

PHP Code:

for(new 03++)
    
DestroyVehicle(a[ax]);

//The loop have index: 0, 1, 2 


Beckett 23/02/2020 05:22 PM

Re: foreach help
 
What's the point of using foreach if you don't want to use an iterator? The idea of foreach is that it stores the equipped slots then loops through them, if you want to loop through all slots then why not use the default `for` loop?


All times are GMT. The time now is 04:33 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.