neverwinter.nim
neverwinter.nim copied to clipboard
scriptcomp: Allow statements in `for` loops
Currently, the for loop syntax is
for (expression_opt; expression_opt; expression_opt) statement
, but it should be
for (statement; expression_opt; expression_opt) statement
Specifically, this should be possible for (int i = 0; i < N; i++) {...}
The scope of the first statement is the scope of the entire block. In other words, the above is equivalent to
{
int i;
for (i = 0; i < N; i++) {...}
}
Consider the following:
for ( object oPC = GetFirstPC() ; GetIsObjectValid(oPC) ; oPC = GetNextPC() ) { ... }
The third entry would also have to be a statement to support that, correct?
Consider the following:
for ( object oPC = GetFirstPC() ; GetIsObjectValid(oPC) ; oPC = GetNextPC() ) { ... }
The third entry would also have to be a statement to support that, correct?
No, in C-family languages, assignment is an operator. It has two operands (left and right, like + or any other operator) and it returns a value (the value that was assigned), and just has the side effect of changing the left operand. This is why you can do a = b = c;
. Since the grouping for binary operators of same priority is right-to-left, that is equivalent to b = c; a = b;
Anything with an operator is an expression. Statements are a superset of that that also allow things like variable declarations.