LOOP

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

LOOP

DEBOER

Hi guys,

How can I create a variable (loop) that counts from 1 to 5 and then starts 1 to 5 and so on. (see v1 below).
Im trying this
compute v1=0.
loop #i=1 to 5.
compute v1=v1 +1.
end loop.
exe.

v1
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5


thanks in advance
Reply | Threaded
Open this post in threaded view
|

Re: LOOP

Shih, Thomas-2
Try the following:

INPUT PROGRAM.
-LOOP #I=1 TO 20. /* LOOP TO NUMBER OF VALUES FOR I
-  LOOP #V=1 TO 5. /* LOOP TO NUMBER OF VALUES FOR V
-   COMPUTE V=#V.
-   END CASE.
-  END LOOP.
-END LOOP.
END FILE.
END INPUT PROGRAM.
FORMATS V(f8.0).
LIST.

Thanks,
Thomas
-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of DEBOER
Sent: Friday, July 01, 2011 4:21 AM
To: [hidden email]
Subject: LOOP

Hi guys,

How can I create a variable (loop) that counts from 1 to 5 and then starts 1
to 5 and so on. (see v1 below).
Im trying this
compute v1=0.
loop #i=1 to 5.
compute v1=v1 +1.
end loop.
exe.

v1
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5


thanks in advance

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/LOOP-tp4541513p4541513.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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

=====================
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: LOOP

Frans Marcelissen-3
In reply to this post by DEBOER
If I understand you correctly:

compute v1=mod($casenum-1, 5)+1.
execute.

Greetz
Frans
> Date: Fri, 1 Jul 2011 02:21:25 -0700

> From: [hidden email]
> Subject: LOOP
> To: [hidden email]
>
> Hi guys,
>
> How can I create a variable (loop) that counts from 1 to 5 and then starts 1
> to 5 and so on. (see v1 below).
> Im trying this
> compute v1=0.
> loop #i=1 to 5.
> compute v1=v1 +1.
> end loop.
> exe.
>
> v1
> 1
> 2
> 3
> 4
> 5
> 1
> 2
> 3
> 4
> 5
> 1
> 2
> 3
> 4
> 5
> 1
> 2
> 3
> 4
> 5
>
>
> thanks in advance
>
> --
> View this message in context: http://spssx-discussion.1045642.n5.nabble.com/LOOP-tp4541513p4541513.html
> Sent from the SPSSX Discussion mailing list archive at Nabble.com.
>
> =====================
> 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