top banner
Gri Commands
1: Introduction
2: Simple example
3: Fancy example
4: Running Gri
5: Programming Gri
6: General Issues
7: X-Y Plots
8: Contour Plots
9: Image Plots
10: Examples
11: Handling Data
12: Gri Commands
13: Gri Extras
14: Evolution of Gri
15: Installing Gri
16: Gri Bugs
17: System Tools
18: Acknowledgments
19: License
20: Newsgroup

21: Concept Index
navigate navigate navigate navigate navigate navigate

12.17: The `if' Command

(See also see If Statements..)
`if {[!] .flag.}|\flag|{{"string1" == "string2"}}'
Control program flow. The `if' block is ended with a line containing `end if'. Optional `else' and `else if' blocks are allowed. Note that rpn expressions are allowed, and a special form of string comparison is allowed, as in the examples below.
     
if .flag.
  # List of Gri commands to be done if .flag. is 1.
  # This list may extend across any number of lines.
end if
If the variable `.flag.' is not equal to 0, do the code between the `if' line and the `end if' line.
if .flag.
  # Commands done if .flag. is 1
else
  # Commands done if .flag. is 0
end if
If the variable `.flag.' is not equal to 0, do the code between the `if' line and the `else' line. If `.flag.' is equal to 0, do the code between the `else' line and the `end if' line.
if ! .flag.
  # Commands done if .flag. is 0
end if
If the variable `.flag.' is equal to 0, do the code between the `if' line and the `end if' line.
if {rpn .flag. 10 <}
  # Commands done if 10 is less than .flag.
end if
If the variable `.flag.' is less than 10, do the code between the `if' line and the `end if' line.
if \smooth
  # Commands done if \smooth is 1
else
  # Commands done if \smooth is 0
end if
If the number stored in the synonym `\smooth' is not equal to 0, do the code between the `if' line and the `else' line. If the synonym stores a representation of a number not equal to zero, do the `else' part. If the synonym contains text that does not decode to a number, generate error message.
if {"\item" == "Temperature"}
  # Commands done if the synonym \item is equal to the
  # indicated text string.
end if
If the synonym `\item' has the value `Temperature' stored in it, do the indicated code.
if {rpn "\item" "Temperature" ==}
  # Commands done if the synonym \item
  # equals indicated text string.
end if
As above, but using the `rpn' calculator (see rpn Mathematics.).
if {rpn "\item" "Temperature" !=}
  # ...
end if
As above, but do the indicated code if `\item' is not equal to `Temperature'.
bottom banner