Evaluator confused by if/else in loops

This works fine on its own:

if (1 == 2) {
    Output("if");
}
else {
    Output("else");
}

Running it inside a loop ends with a syntax error:

For

for (i = 0; i < 5; i++) {
    if (1 == 2) {
        Output("if");
    }
    else {
        Output("else");
    }
}

While

i = 0;
while (i < 5) {
    if (1 == 2) {
        Output("if");
    }
    else {
        Output("else");
    }
    i++;
}


Similar to

Thanks, fixed in the next update.

1 Like

The Evaluator does not replace the old scripting and commands. Rather, it is somewhere between the two and works in conjunction with them. It is less powerful than full-blown scripting, but also has lower overheads and is guaranteed not to get stuck in loops (since it has no loops!). This allows it to be used in places where calling a normal script could cause problems.

So there are loops in Evaluator though.

Let's play with the While loop a bit more.

i = 0;
while (i < 5) {
	Output("Hello");
    i++;
}

We can enhance the output a bit:

We can check and increment the counter in one go:

But we can't do both:

The For loop behaves similarly, but the coding style is a bit awkward:

for (i = 0; i++ < 5;) {
	Output("Hello");
}

Not on a computer to test: what about casting i as str in the Output statement?

Like so?

1 Like

Deleted by author

BTW, JScript is cool with this style.

var i;
for (i = 0; i++ < 5;) {
	DOpus.Output("Hello " + i);
}

i = 0;
while (i++ < 5) {
	DOpus.Output("Hello " + i);
}

Thanks, fixed in the next beta!

1 Like