Raised This Month: $ Target: $400
 0% 

Creating static inside loop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 06-13-2014 , 18:33   Re: Creating static inside loop
Reply With Quote #1

Second.
Quote:
Originally Posted by hornet View Post
Never create a new variable inside a loop.
https://forums.alliedmods.net/showth...highlight=loop
I don't know if this also аpplies to statics, but I think it's something sort of.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-13-2014 , 19:45   Re: Creating static inside loop
Reply With Quote #2

It's essentially the same thing except for scope. Generally, if you create the variable inside the loop, it cannot be used outside the loop. The fact that it is static will mean there won't be any significant performance degradation after it has run once. Regardless, it always best to stick to the "never create variables inside a loop" recommendation.
__________________
fysiks is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 06-13-2014 , 21:09   Re: Creating static inside loop
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
it always best to stick to the "never create variables inside a loop" recommendation.
Variables should always be declared as close to the scope they're used in as possible, unless doing so reduces performance, which is not the case here. So leaving the static variable declaration inside the loop is the right thing to do.
__________________
hleV 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 21:05.


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