Question

What's wrong with the following?

I'm getting a syntax error on the last line, just after the if

Module mytest

int n = if (3 > 2) 1; else 0;

thx, --Dennis.

Was it helpful?

Solution

Top-level declarations in Rascal (which include declarations in the console) expect an expression on the right-hand side, so you would need to instead say:

int n = ( 3 > 2 ) ? 1 : 0;

If you are inside a function, there is an inconsistency in what is allowed, so this should work fine:

n = if (3 > 2) 1; else 0;

but what you have above also won't work in that context.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top