Assignment Statement

Home • Gallery • Tutorials • Download • Purchase • Site Map
 

Assignment Statement Syntax

The assignment statement is used to assign a value to a variable in a Fractal Science Kit fractal program.

The basic syntax is:

<Variable> = <Expression>

The expression is evaluated and the resulting value is assigned to the variable.

Be forewarned that unlike some other languages, assignment does not produce a value, so statements with several variables separated by the = character cannot be used to initialize several variables to the same value as in:

a = b = c

This, in fact, will set a to the result of the expression b=c. That is, the 2nd = is interpreted as the equality comparison operator, the expression b=c is evaluated, and the resulting Boolean value is assigned to a.

Several additional forms of assignment combine an arithmetic operation with the assignment:

<Variable> += <Expression>
<Variable> -= <Expression>
<Variable> *= <Expression>
<Variable> /= <Expression>
<Variable> ^= <Expression>
<Variable> %= <Expression>

These are functionally equivalent to the following:

<Variable> = <Variable> + (<Expression>)
<Variable> = <Variable> - (<Expression>)
<Variable> = <Variable> * (<Expression>)
<Variable> = <Variable> / (<Expression>)
<Variable> = <Variable> ^ (<Expression>)
<Variable> = <Variable> % (<Expression>)

Example:

z += 1    ' z = z + 1
z *= 2    ' z = z * 2
z *= w+1  ' z = z * (w+1)
z /= w-1  ' z = z / (w-1)

In the above example, the trailing comments provide functionally equivalent statements to those to the left of the comments.

 

Copyright © 2004-2017 Hilbert, LLC
All rights reserved