There are 5 types of control loops in tnimage: for loops, while loops, implicit loops, explicit loops, and the ever-popular goto. The syntax is simple and C-like:
for loops initialize the first argument at the beginning, execute as long as the second argument is true, and execute the 3rd argument at the end of each loop. The entire for loop is only executed once. The loop body must be surrounded by braces. Unlimited nested loops are permitted.
for(k=0; k<GRAINS; k++)
{
print("grain was at ", spotx(k), spotx(y), "\n");
}
while loops execute indefinitely as long as the argument is true. The loop body must be surrounded by braces.
while(i<96)
{ x+=100;
y+=100;
i++;
d = cdensity(x,y,34);
print("Density of well no. ", i, " is ", d, "\n");
}
implicit loops Any math statement not in a for or while loop will automatically be executed for every pixel in the current image or currently-selected area. This makes the notation extremely compact:
i*=2;
multiplies all pixels in the currently-selected region by 2.
explicit loops As described earlier, enclosing a group of statements in the ``loop'' structure makes certain that they will be evaluated as image algebra statements. For example:
loop
{
... statements ...
}
Statements inside explicit loops must be enclosed in braces. Any macro commands inside an explicit loop will cause an error.
goto Jumps to specified line number. Statement labels are not supported yet.
fft(1,2);
k++;
if(k<5) goto(1);