Next: Drawing commands, Previous: Examples, Up: Top
Here is a short introductory example to the Asymptote
programming
language that highlights the similarity of its control structures
with those of C and C++.
// This is a comment. // Declaration: Declare x to be a real variable; real x; // Assignment: Assign the real variable x the value 1. x=1.0; // Conditional: Test if x equals 1 or not. if(x == 1.0) { write("x equals 1.0"); } else { write("x is not equal to 1.0"); } // Loop: iterate 10 times for(int i=0; i < 10; ++i) { write(i); }
Loops, together with user-defined functions, are illustrated
in the files wheel.asy
and cube.asy
in the
animations subdirectory of the examples directory. These examples use the
gifmerge
command to merge
multiple images into a
gif animation, using the ImageMagick
convert
program.
Asymptote
also supports while
, do
, break
, and
continue
statements just as in C/C++. In addition, it supports
many features beyond the ones found in those languages.