AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Loop headers (https://forums.alliedmods.net/showthread.php?t=325145)

Vieni 06-09-2020 17:55

Loop headers
 
The question would be that, which option uses less cpu:
HTML Code:

1. for(new i; i < ArraySize(dynamicArray); i++)

OR

2.
new lArraySize = ArraySize(dynamicArray)
for(new i; i < lArraySize; i++)

So basically I'm asking if the functions in the header called everytime it's being looped

Bugsy 06-09-2020 18:03

Re: Loop headers
 
The second one. You want to aim at having the least number of native calls. Storing the value in a variable will result in ArraySize() being called only once, instead of ArraySize number of times.

Vieni 06-09-2020 18:57

Re: Loop headers
 
And why is that if I create a for loop like this
HTML Code:

for(new i; statement; i++)
the i variable ain't restarted at every loop creating a possible infinite loop?

Then does this whole stuff look something like this?
HTML Code:

for(<done at start>; <checked every loop>; <done every loop>)

Bugsy 06-09-2020 18:59

Re: Loop headers
 
You answered your own question. The first part is done when the loop is initiated.

Here's another way to look at it.
PHP Code:

new i;

for ( 
15 <= 20 i++ )

     
//15 , 16, 17, 18, 19, 20



Vieni 06-09-2020 19:01

Re: Loop headers
 
Quote:

Originally Posted by Bugsy (Post 2704868)
You answered your own question. The first part is done when the loop is initiated.

Here's another way to look at it.
PHP Code:

new i;

for ( 
15 <= 20 i++ )

     
//15 , 16, 17, 18, 19, 20



Well, thx, appreciate it!

HamletEagle 06-10-2020 03:12

Re: Loop headers
 
To add to the first question:
If you used sizeof then for(...; i < sizeof; i++) would be fine since regular array sizes are known at compile time.

pattytaylor 06-29-2020 23:07

Re: Loop headers
 
Thx, appreciate it!


All times are GMT -4. The time now is 05:44.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.