Jump to content

Proper For Loops?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
thieflock

thieflock

    Newbie

  • Members
  • PipPip
  • 29 posts
When declaring variables for a For Loop is it better to declare them at the top after the main method or only within the For Loop.

Thank you.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
It depends on where else you will use them, and your coding style.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Guest_lamagra_*

Guest_lamagra_*
  • Guests
thieflock is right.

If you plan to use your variable in any part of your program you need to create it outside of the loop (unless you are going to pass it to methods within the loop). If it is only being used for a counter or temp storage then do it inside the loop.