Pregunta

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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top