AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   neatest way to have 2 for loops co-exist (https://forums.alliedmods.net/showthread.php?t=25934)

SubStream 03-23-2006 22:02

neatest way to have 2 for loops co-exist
 
which is better
Code:
for ( gi_cvarnum = 0; gi_cvarnum < 80; gi_cvarnum++ )     {         gi_cvar = g_cvars[gi_cvarnum]                 for ( gi_playernum = 0; gi_playernum < gi_playercnt; gi_playernum++ )         {             gi_playerID = gi_players[gi_playernum]
or is this also correct?
Code:
for ( gi_cvarnum = 0; gi_cvarnum < 80; gi_cvarnum++ ) for ( gi_playernum = 0; gi_playernum < gi_playercnt; gi_playernum++ )     {         gi_cvar = g_cvars[gi_cvarnum]                 gi_playerID = gi_players[gi_playernum]
Someone please tell me if both are the same and which one is better to use. I need both conditions to be true and use gi_cvar and gi_playerID together in the same statement following these conditions.

capndurk 03-23-2006 23:22

The second one isn't correct because you're missing the first { bracket for the first for loop, but even then, I'd still go with the first example, unless you need to repeatedly assign gi_cvar within the second loop.

akysiev 03-24-2006 07:08

Actually if the inner for loop is the only block of code within the outer for loop in the second way, then it should be fine. Anyways, go with the first. The variable assignment isn't exactly taxing but its still nice to keep a good scope hierarchy.


All times are GMT -4. The time now is 16:41.

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