Credits | Overview | Plotting Styles | Commands | Terminals
--- | --- | --- | --- | ---

## if

Syntax:

          if (<condition>) { <commands>;
                 <commands>
                 <commands>
          } else if (<condition>) {
                 <commands>
          } else {
                 <commands>
          }

This version of gnuplot supports block-structured if/else statements. If the keyword if or else is immediately followed by an opening "{", then conditional execution applies to all statements, possibly on multiple input lines, until a matching "}" terminates the block. If commands may be nested.

Prior to gnuplot version 5 the scope of if/else commands was limited to a single input line. Now a multi-line clause may be enclosed in curly brackets. The old syntax is still honored but cannot be used inside a bracketed clause.

Old syntax:

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

If no opening "{" follows the if keyword, the command(s) in <command-line> will be executed if <condition> is true (non-zero) or skipped if <condition> is false (zero). Either case will consume commands on the input line until the end of the line or an occurrence of else. Note that use of ; to allow multiple commands on the same line will _not_ end the conditionalized commands.