Vectors and Loops

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

israpound
Posts: 1
Joined: Thu Aug 04, 2011 8:37 pm

Vectors and Loops

I have a couple of questions about vectors\loops:

First question, using the example
below (I made this up just to illustrate the question), when the data is read, var2 will be read, but will it then read
var7 or var6? In other words is the second read relative to the first
read? It appears after some testing that it will read var7 rather than start with var6, but I can't
be sure.

vector A=var1 to var5.
vector B=var6 to var10.
loop #C=1 to 4.
do if(A(#C=2) and B(#C)=3).
compute test=1.
end if.
end loop.
exe.

Second question, using basically the same sample;

vector A=var1 to var5.
vector B=var6 to var10.
loop #C=1 to 4.
do if(A(#C=2) and B(#C)=3).
compute test=A(#C)*B(#C-1).
break.
end if.
end loop.
exe.

What I am wondering is once the condition is found, given the break statment can the compute statement
use a value with occurs prior to the condition, e.g., B(#C-1)?

Any response will be appreciated, Thanks.
ramiav
Posts: 6
Joined: Sun Sep 28, 2008 11:43 am

Re: Vectors and Loops

first of all, i think you missed a Parentheses:
do if(A(#C=2) and B(#C)=3).
should be:
do if A(#C)=2 and B(#C)=3).

now i don't see any problam with your syntax.
it will read var6, var7 with no problem,
and there is no problem with your second syntax:
compute test=A(#C)*B(#C-1).
you can also do this:
compute test=A(#C)*B(#C+1).
it is a regular array and can do anything an array should do...

Who is online

Users browsing this forum: No registered users and 2 guests