Navigation
Synopsis Conditional statement.
Syntax
  • if ( Exp ) Statement;
  • if ( Exp ) Statement1 else Statement2;
Types
Exp if ( Exp ) Statement;
bool void
Exp Statement1 Statement2 if ( Exp ) Statement1 else Statement2;
bool T1 T2 lub(T1, T2)
Description The test Exp is evaluated and its outcome determines the statement to be executed: Statement1 if Exp yields true and Statement2 otherwise. The value of an if-then statement is equal to Statement when its test is true. Otherwise it is void. The value of an if-then-else statement is the value of the statement that was executed.
Examples
rascal>if( 3 > 2 ) 30; else 40;
int: 30
rascal>x = if( 3 > 2 ) 30; else 40;
int: 30
rascal>if( 3 > 2 ) 30;
int: 30
An if-then statement yields void when its test is false (demonstrated by the ok that is printed by the Rascal system):
rascal>if( 2 > 3 ) 30;
ok

Questions
Question [1].
The type of if( -5 > -6 ) 10; else 20; is

Question [2].
The type of if( 18 > -7 ) "R2-D2"; else "Jar Jar Binks"; is

Question [3].
if( -15 > 19 ) 10; else 20; == 



Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.