1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
<HTML>
<HEAD>
<TITLE>Looping</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<P><A NAME="execlooping"></A>
<font size="+3" color="green"><B>Looping</B></font></P>
<P>
<CODE>DO</CODE> loops can only be used in
script files. <CODE>DO</CODE> loops must be terminated with
<CODE>ENDDO</CODE>. The range of the <CODE>DO</CODE> loop can be any expression
resulting in a vector. The loop will execute a number of times equal to
the length of the loop range vector, with the loop variable taking on the
values of each element of the loop range vector. Nested loops are allowed.
The looping variable is created as a scalar variable.</P>
<P>
<font size="+2" color="green">Example</font></P>
<P>
The variable <CODE>j</CODE> below will be made into a scalar:</P>
<font color="blue"><Pre>
... !
DO j = x ! x must be a vector, loop will execute len(x) times with
... ! j successively taking on the value of each element of x
ENDDO !
... !
</PRE></font>
<P>
<font size="+2" color="green">Example</font></P>
<font color="blue"><PRE>
... !
DO I = [2:20:4] ! the loop will execute 5 times
... !
ENDDO !
... !
</PRE></font>
<P><font size="+2" color="green">Example</font></P>
<font color="blue"><PRE>
...
X = [1;3;5;7;9;10;12;14]
DO I = X^2 ! the loop will execute LEN(X)=8 times with
... ! I taking on the values [1;9;25;49;81;100;144;196]
ENDDO
...
</PRE></font>
<P>
<a href="branching.htm"><img src="../shadow_left.gif">
<font size="+1" color="olive">Branching</font></a><br />
<a href="ifthen.htm"><img src="../shadow_right.gif">
<font size="+1" color="olive">Conditional statements</font></a>
</P>
</BODY>
</HTML>
|