A Gamma or Lisp expression to test.
A statement to perform if the condition is non-nil.
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
See the introduction or the Monitor Window section of the Photon Functions chapter (Tutorial One), or the Starting Programs section of the Common Functions for Any Program chapter (Tutorial Two) in the Cogent Tools Demo and Tutorials book for examples of this function used in context.