Examples - programming

Print

/* display text and result of expressions */
print "add", 2+3, "mult", 2*3

/* this will be printed on 2 lines */
print "add", 2+3; print "mult", 2*3

/* this will be printed on 1 line */
print "add", 2+3,; print " mult", 2*3

/* insert blank line */
print "add", 2+3; print; print "mult", 2*3

/* last expression is printed automatically */
a=2; b=3; c=a*b

/* last expression is not printed if there is a semicolon at the end */
a=2; b=3; print c=a*b; d=a+b;

Conditions

/* simple if expression */
a=2;b=3; if(a>b, a, b)

/* asignment to variable inside if */
a=5;b=2; if(a>b, c=a, c=b)

/* nested if */
a=15; if(a>10, if(a>100,3,2), 1)

/* relative goto */
a=1;b=7; if(a>b, 0, gotor4); print "a>b"; c=a; gotor3;
print "a<=b"; c=b; print "c=", c

/* goto label */
a=6;b=5; if(a>b,0,goto label1); print "a>b"; c=a; goto end;
label1: print "a<=b"; c=b;  end: print "c=", c

Loops

/* loop which contains a simple expression */
S=0; for(x,1,10, S=x*2+S*3); print S

/* loop which contains commands */
S=0; x=1; begin: print "x=",x,"S=",S=x*2+S*3; x++; if(x<=10, goto begin, S)

/* list created by evaluating expression, variable is incremented by 1 */
listfor(x,1,10,x^2)

/* list created by evaluating expression, variable is incremented by 2 */
S=0; x=1; begin: S=(S,x^2); x=x+2; if(x<=10, goto begin, S=(S[1, count S-1]))

/* matrix which contains combination numbers */
rowsfor(i,1,9, listfor(j,1,9, (j+i) ncr i))

/* matrix which has 5 rows and 10 columns */
rowsfor(i,1,5, listfor(j,1,10, i*j))