Raised This Month: $ Target: $400
 0% 

neatest way to have 2 for loops co-exist


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SubStream
Veteran Member
Join Date: Aug 2005
Location: USA
Old 03-23-2006 , 22:02   neatest way to have 2 for loops co-exist
Reply With Quote #1

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.
SubStream is offline
capndurk
Senior Member
Join Date: Feb 2006
Old 03-23-2006 , 23:22  
Reply With Quote #2

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.
capndurk is offline
akysiev
Junior Member
Join Date: Mar 2006
Location: Earth
Old 03-24-2006 , 07:08  
Reply With Quote #3

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.
akysiev is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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