manpagez: man pages & more
info gnuplot
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.9 if

The if command allows commands to be executed conditionally.

Syntax:

 
      if (<condition>) <command-line> [; else if (<condition>) ...; else ...]

<condition> will be evaluated. If it is true (non-zero), then the command(s) of the <command-line> will be executed. If <condition> is false (zero), then the entire <command-line> is ignored until the next occurrence of ‘else‘. Note that use of ‘;‘ to allow multiple commands on the same line will _not_ end the conditionalized commands.

Examples:

 
      pi=3
      if (pi!=acos(-1)) print "?Fixing pi!"; pi=acos(-1); print pi

will display:

 
      ?Fixing pi!
      3.14159265358979

but

 
      if (1==2) print "Never see this"; print "Or this either"

will not display anything.

else:

 
      v=0
      v=v+1; if (v%2) print "2" ; else if (v%3) print "3"; else print "fred"

(repeat the last line repeatedly!)

See reread for an example of how if and reread can be used together to perform a loop.


© manpagez.com 2000-2024
Individual documents may contain additional copyright information.