navigation map

Chapters:
  1: Introduction
  2: Simple example
  3: Invocation
  4: Finer Control
  5: X-Y Plots
  6: Contour Plots
  7: Image Plots
  8: Examples
  9: Gri Commands
  10: Programming
  11: Environment
  12: Emacs Mode
  13: History
  14: Installation
  15: Gri Bugs
  16: Test Suite
  17: Gri in Press
  18: Acknowledgments
  19: License

Indices:
  Concepts
  Commands
  Variables
index.html#Top ListOfGriCommands.html#ListOfGriCommands Gri: `help' command Gri: `ignore' command index.html#Top Gri: `ignore' command

9.3.17: `if'

(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 greater 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'.

navigation map