if
if — conditionally evaluates statements.
if (condition) statement [else statement]
conditionA Gamma or Lisp expression to test.
statementA statement to perform if the condition is non-nil.
The evaluation of the statement that corresponds
to the satisfied condition.
The if statement evaluates its
condition and tests the result. If the result is
non-nil, then the
statement is evaluated and the result returned.
The else option allows for another statement. If the
condition is nil, the else
statement (if included) is evaluated and the result returned. This statement
could be another if statement with another condition
and else statement, etc., permitting multiple
else/if constructs. The entire
else option can be omitted if desired.
![]() | |
|
Gamma>x = 5;5Gamma>y = 6;6Gamma>if (x > y) princ("greater\n"); else princ("not greater\n");not greater tGamma>
The following code:
name = "John";
age = 35;
if ((name == "Hank") || (name == "Sue"))
{
princ("Hi ", name,"\n");
}
else if ((name == "John") && (age < 20))
{
princ("Hi ", name," Junior\n");
}
else if ((name == "John") && (age >= 20))
{
princ("Hi ", name," Senior\n");
}
else
{
princ("I don't know you\n");
}Will produce the following results:
Hi John Senior