foreach循环
{num = 0}
{gmat = {10, 20, 30, 40}}
{foreach(elem = gmat); num++}
Element {num}: {elem}
{endloop}
我们可以来完成阶乘计算的功能
{num = 0}
{gmat = {1, 2, 3, 4,5,6,7,8,9}}
{foreach(elem = gmat); num++}
{fact = 1}
{for(i = 1; i <= elem; i++)}
{fact = fact * i}
{endloop}
Element {num} ({elem}!): {fact}
{endloop}
通过for计算指定角度的正弦和余弦值:
{for (a=0; a<=3.1415926; a+=3.1415926/12)}
Angle:{a, %6.4f} Sin:{sin(a), %6.4f} Cos:{cos(a), %6.4f}
{endloop}
while循环输出字符,cr()在这里表示换行符,大括号可以同时包括多行代码。
{
i = 0;
while(i < 5);
i; cr();
i++
endloop
}
计算 1 到 10 的每个数字的平方,同时检查平方结果是否是偶数或奇数。
{i = 1;}
{while(i <= 10);}
{square = i * i;}
{if(square % 2 == 0)}
Number {i} squared is {square}, which is even.
{else}
Number {i} squared is {square}, which is odd.
{endif}
{i++;}
{endloop}
同时应用while,for,if的案例
{numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}
{stop_number = 10}
{i = 0}
{while(i < stop_number)}
{current_number = numbers[i]}
{if(current_number % 2 == 0)}
{ {fact = 1}}
{ for(j = 1; j <= current_number; j++)}
{ fact = fact * j}
{ endloop}
Number {current_number} is even, its factorial is {fact}.
{else}
{ square = current_number * current_number}
Number {current_number} is odd, its square is {square}.
{endif}
{i++}
{endloop}
九九乘法的显示
{for (i = 1; i <= 9; i++)}
{for (j = 1; j <= 9; j++)}
{product = i * j}
{if(j == 1)}
{cr()}
{endif}
{product, %2d} x {j, %2d} = {i*j, %2d}
{endloop}
{endloop}