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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top