home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-02-18 | 1.2 KB | 50 lines | [TEXT/RLAB] |
- for:
-
- The RLaB for statement is NOT similar to the C for statement.
- The correct usage is best shown by example...
-
- Example:
-
- > for(i in 1:4) {
- > for(j in 1:5) {
- > m[i;j] = i+j;
- > }
- > }
-
- The above shows a nested set of for statements. i and j are
- automatically initialized to have the values of the vector
- expressions `1:4' and `1:5'. Each loop proceeds until i and j
- have been assigned each element of their respective vector
- expressions.
-
- The vector in the for statement can be any expression that
- evaluates to a SCALAR or a MATRIX. If the expression evaluates
- to a SCALAR the body of the for statement is executed ONCE. If
- the expression evaluates to an empty-matrix ( `[]' ), then the
- loop is not executed at all.
-
- The for statement can be also be used to loop through the
- elements of a LIST.
-
- Example:
-
- > xlist = << Mass = sqrt(200); Inertia = eye(3,3); xdot = [1,2,3] >>
- Inertia Mass xdot
- > for( i in members(xlist) )
- {
- xlist.[i]
- }
- Inertia =
- matrix columns 1 thru 3
- 1 0 0
- 0 1 0
- 0 0 1
- Mass =
- 14.14
- xdot =
- matrix columns 1 thru 3
- 1 2 3
-
-
- See Also: VECTOR
-