concept conditional in category gnuplot

appears as: conditionals
Gnuplot in Action

This is an excerpt from Manning's book Gnuplot in Action.

The other two operators are comparison operators for use in conditionals: eq (equal) and ne (not equal). The first returns true if both of its arguments are equal, and the second returns true if they differ:

11.1. Loops and conditionals

Gnuplot has support for loops and conditionals: this makes it possible to automate repeated tasks. In contrast to the inline loops that we encountered earlier (see section 5.4), the control structures introduced in this section are more general. They can be applied to any command, or any combination of commands—not just a single plot or set command, as was the case for inline loops. In addition to two different loops and a conditional construct, there’s also a special operator that calculates the sum of a set of numbers. Let’s look at all of them in detail; table 11.1 provides a summary.

Table 11.1. Gnuplot loop constructs and conditionals

Syntax

Example

do for [var=start:end:increment] {
  statement
  statement
 ...
}
do for[k=1:10] {
    print k
}
do for [var in tokenstring] {
 statement
 statement
 ...
}
do for [s in "abc uvw xyz"] {
    print s
}
while( condition ) {
 statement
 statement
 ...
}
x = 0
while( x < 10 ) {
    x = x + 1
    print x
}
if( condition ) {
 statement
 statement
 ...
} else {
  statement
  statement
  ...
}
x = 0
if( x < 0 ) {
    print "Negative"
} else {
    print "Not negative"
}