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

Program Statements

A Fractal Science Kit fractal program is made up of statements. A statement is a program instruction that is processed as a unit during compilation. Some statements include blocks of other statements. Blocks of statements are usually enclosed by braces ({...}). Within these blocks, some of the statements may include additional blocks of statements, and so on.

Some of the text within the program is for the purpose of documenting the code and is not meant to be processed by the compiler. These are called comments. Comments are identified by the comment character, a single quote ('). The semi-colon (;) is an alternate comment character. Any text found after the comment character on a given line is ignored by the compiler.


' This is a comment block.
z = 0 ' This is a trailing comment.

This example illustrates a comment block and a trailing comment.

Sometimes the program text is too long to fit on a line without the line becoming inordinately long. Since the compiler uses the end of the line to delineate statements, simply splitting the line into 2 parts would cause a compiler error. However, you can use the line continuation character, the backslash (\), to handle this situation. During compilation, the compiler will join any line ending with the line continuation character, with the following line.


n = (z.x-p0.x)*(p1.x-p0.x) + \

This example illustrates how to continue a statement onto the next line.

Multiple consecutive lines ending in the line continuation character can be used to allow any number of lines to be processed as a single statement by the compiler.


Complex Triangle.Area(Triangle t) {
  return Abs(0.5 * ( \
    t.A.x * (t.B.y - t.C.y) + \
    t.B.x * (t.C.y - t.A.y) + \
    t.C.x * (t.A.y - t.B.y)   \

The inline function defined above uses line continuation to split the return statement into 5 lines for clarity.

On the other hand, sometimes you want to combine 2 or more statements on a single line. To place multiple statements on the same line, separate the statements with the statement separator character, a colon (:).


result[n] = p0 + (p1-p0)*factor : n += 1
result[n] = p1 + (p0-p1)*factor : n += 1

The above example places 4 statements on 2 lines.


switch (Triangle) {
  case TriangleTypes.T_60_60_60: ang = Math.PI / 3
  case TriangleTypes.T_30_60_90: ang = Math.PI / 6
  case TriangleTypes.T_45_45_90: ang = Math.PI / 4

Another common use of the statement separator character is to join the case statement with its associated block when the block is a single statement, as shown above.


Copyright © 2004-2016 Hilbert, LLC
All rights reserved