if (condition) statement [else statement]
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; 5 Gamma> y = 6; 6 Gamma> if (x > y) princ("greater\n"); else princ("not greater\n"); not greater t Gamma>
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
Copyright © 1995-2006 by Cogent Real-Time Systems, Inc. All rights reserved.