ChaosPro Home
Introduction
What's New
Palettes
Using Formulas
Layering in ChaosPro
Rendering
Fractal Parameter Windows
Windows
Menu
3D Transformations
Animations
Formula Compiler
Writing Formulas
Language Reference
Introduction
Basic Syntax
Datatypes
Constants
Variables
Expressions
Operators
Functions
Control Structures
if...else if...else
while
do...while
for
break
return
import
Compiler Directives
Functions
Interface to ChaosPro
Special Features, Notes...
Compatibility
Fractal Type Reference
Tutorials
Appendix
CHAOSPRO 4.0
Release 4.0
.

While loop

While loops are the simplest type of loop in ChaosPro. They behave just like their C counterparts. The basic form of a while statement is:

while (expr)
{
  statement
}

The meaning of a while statement is simple: It tells ChaosPro to execute the nested statement(s) repeatedly, as long as the while expression evaluates to TRUE. The value of the expression is checked each time at the beginning of the loop, so even if this value changes during the execution of the nested statement(s), execution will not stop until the end of the iteration (each time ChaosPro runs all the statements in the loop is one iteration). Sometimes, if the while expression evaluates to FALSE from the very beginning, the nested statement(s) won't even be run once.

Like with the if statement, you must group statements within the same while loop by surrounding a all of these statements with curly braces. While loops of course can be nested.

Example

i = 1;
sum=0;
while (i <= 10)
{
  sum=sum+i; // sum up the numbers from 1 to 10
}