6.3 For Loops

For loops may be used to execute a series of commands multiple times. PyXPlot’s for command has the syntax:

for <variable> = <start> to <end> {step <step>} {loopname <name>}
 {
  ....
 }

The first time that the script block is executed, the variable named at the start of the for statement has the value given for start. Upon each iteration of the loop, this is incremented by amount step. The loop finishes when the value exceeds end. If step is negative, then end is required to be less than or equal to start. A step size of zero is considered to be an error. The iterator variable can have any physical dimensions, so long as start, end and step all have the same dimensions, but the iterator variable must always be a real number. If no step size is given then a step size of unity is assumed. As an example, the following script would print the numbers 0, 2, 4, 6 and 8:

for x = 0 to 10 step 2
 {
  print x
 }

The same rules concerning the placement of brace characters apply to the for command as to the if command.

The optional loopname which can be specified in the for statement is used in conjunction with the break and continue statements which will be introduced in Section 6.7.