Hello,
Why is it not possible to create a variable inside the loop?
Instead of:
local int i;
for (i = 0; i < 5; i++) {…}
to:
for (int i = 0; i < 5; i++) {…}
or:
for (local int i = 0; i < 5; i++) {…}
it would make binary templates much cleaner.
Hello,
Why is it not possible to create a variable inside the loop?
Instead of:
local int i;
for (i = 0; i < 5; i++) {…}
to:
for (int i = 0; i < 5; i++) {…}
or:
for (local int i = 0; i < 5; i++) {…}
it would make binary templates much cleaner.
Being able to define variables like this would be nice and we are going to look at adding this to our next version if there are no major issues found. Originally, we did not add this in because scoping works differently for variables in Binary Templates than in regular C. In C if you create a variable inside a { } block, that variable does not exist out of the block but in Binary Templates it continues to exist. We were concerned about the extra variables defined in a for loop continuing to exist, but being able to define variables in this way is so nice that we really should allow it.
Graeme
SweetScape Software
Perhaps any variables defined inside loop delimiters {}
should either require an explicit local (for templates) or else be implicitly local, in both templates and scripts (where they’d automatically be local anyway).
And it’s a short step, probably, from the original suggestion to allowing:
for ( int i = 0; ...) _statement_
along with allowing i to be used within statement.
or similarly
while ( (char c = ...) _boolean expression using c_) _statement_
I don’t remember whether those are in modern C syntax or not. (Of course, feel free to ignore this part of the suggestion if they aren’t).