write an infinite for loop in where variable is not declared
Answers
Explanation:
statement provides a compact way to iterate over a range of values. The for statement has a general form and, as of 5.0, an enhanced form that you can use when performing simple iterations over arrays and collections. The general form of the for statement can be expressed like this:
Explanation:
Developer's point of view aside, the compiler is the only one who cares. If you put the declaration inside a block, you may make it easier for the compiler with registry allocation because it's more obvious what is the usage scope of the variable. But hey, compilers are smart today and you wouldn't make much of a difference (see loop invariant code motion mentioned by @Bas Brekelmans).
You cannot rely on simple measurement as suggested in comments. If there really is a deterministic difference between RAM usage, my guess would be that the compiler makes a different decision somewhere for the two versions, it works heuristically anyway.
To summarize, always prefer readability to optimization, especially with such low level details. The compilers does this job better than you.