Vector & Loop VS. Do Repeat?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Vector & Loop VS. Do Repeat?

Eric Langston

I believe that using Vector and Loop together accomplishes the same thing as the Do Repeat command.  Eg:

 

Vector V = var1 to var10.

Loop #T = 1 to 10.

If V(#T) = 1234 Dummy_Code = 1.

If V(#T) = 4567 Dummy_Code = 1.

End loop.

 

Do repeat V = var1 to var10.

If V = 1234 Dummy_Code = 1.

If V = 4567 Dummy_Code = 1.

End repeat.

 

 

I understand that the Do Repeat command just parses together the commands as if they were written out fully and then passes it to the processor.  So, does that mean that the Vector-Loop construct requires less computation effort by comparision?

 

The Do Repeat command seems a bit more ‘friendly’.  So, if there isn’t a difference, I’ll just default to using that.

 

Thanks!!

 

-Eric

 

---

Eric Langston

IBM SPSS Certified

Research Analyst

Human Capital Research Corporation

500 Davis Street, Suite 1002

Evanston, IL 60201

(847) 475-7580  Phone

(847) 475-7584  Fax

 

 

Reply | Threaded
Open this post in threaded view
|

Re: Vector & Loop VS. Do Repeat?

Maguin, Eugene
Eric,

In your example, I agree with you. I can't comment on whether there are
execution speed differences. However, there are many instances where you
must use one or the other to accomplish your task.

Gene Maguin

>>I believe that using Vector and Loop together accomplishes the same thing
as the Do Repeat command.  Eg:

Vector V = var1 to var10.
Loop #T = 1 to 10.
If V(#T) = 1234 Dummy_Code = 1.
If V(#T) = 4567 Dummy_Code = 1.
End loop.

Do repeat V = var1 to var10.
If V = 1234 Dummy_Code = 1.
If V = 4567 Dummy_Code = 1.
End repeat.

I understand that the Do Repeat command just parses together the commands as
if they were written out fully and then passes it to the processor.  So,
does that mean that the Vector-Loop construct requires less computation
effort by comparision?

The Do Repeat command seems a bit more 'friendly'.  So, if there isn't a
difference, I'll just default to using that.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Vector & Loop VS. Do Repeat?

Richard Ristow
At 11:18 AM 11/18/2009, Gene Maguin wrote:

In your example, I agree [that DO REPEAT is easier than VECTOR/LOOP logic]. I can't comment on whether there are execution speed differences. However, there are many instances where you must use one or the other to accomplish your task.

Expanding on that, I can think of the following, likely not exhaustive:

* DO REPEAT is easier to write. You don't have to have the number of elements in the list in the code.

* If the variables in the list aren't contiguous, VECTOR won't work but DO REPEAT will. (It works clumsily; you have to list every variable in the list for every stand-in variable.)

* If you need to access your variables in anything beyond straight once through order, VECTOR is almost mandatory. In this case, you won't have a simple LOOP over the vector. See, for example,

    Date:    Fri, 5 Jun 2009 01:12:46 -0400
    From:    Richard Ristow <[hidden email]>
    Subject: Re: Emergency Help!- Maybe Loops and Vectors
    To:      [hidden email]

* XSAVE will work within a LOOP but not within a DO REPEAT. (Admittedly, XSAVE isn't as important as it used to be; many effects we used to get using XSAVE can be translated to VARSTOCASES logic.)
X-ELNK-Received-Info: spv=0;
X-ELNK-AV: 0
X-ELNK-Info: sbv=0; sbrc=.0; sbf=0b; sbw=000;
X-Antivirus: AVG for E-mail 8.5.339 [270.12.53/2154]
Content-Type: multipart/mixed; boundary="=======AVGMAIL-2B4344F4======="

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD