Repeat command blocks

45 views
Skip to first unread message

jens

unread,
Jan 11, 2011, 11:39:10 AM1/11/11
to E-Prime
Hello

Does anyone have an idea on how to repeat a block of commands a number
of times? I have gone through the E-Basic but I can't get the
Do...Loop or For...Next commands to work for me.

Example:

IF c.getAttrib("bet") = 1 THEN
WritePort &H378,64
sleep 5
WritePort &H378,0
sleep 5

*repeat 5 times

ELSEIF c.getAttrib("bet") = 2 THEN
WritePort &H378,64
sleep 10
WritePort &H378,0
sleep 10

*repeat 5 times

END IF

Michiel Spape

unread,
Jan 11, 2011, 11:58:21 AM1/11/11
to e-p...@googlegroups.com
Ha,
Sorry to other people whom I haven't replied to yet. I saw loads of code and my flu told my brain that I shouldn't bother. Perhaps the flu is rampant at the PST headquarters too? Anyway, this however, we have sorted out quickly.

DIM I as INTEGER
IF c.GetAttrib("bet") = 1 THEN
FOR I = 1 to 5


WritePort &H378,64
sleep 5
WritePort &H378,0
sleep 5

NEXT I 'thus repeats 5 times
ELSE
FOR I = 1 to 5


WritePort &H378,64
sleep 10
WritePort &H378,0
sleep 10

NEXT I 'thus repeats 5 times
END IF

There's prettier ways to code this, such as
Dim I as integer
FOR I = 1 to 5
WritePort &H378,64
sleep cInt(c.GetAttrib ("bet")) * 5
WritePort &H378,0
sleep cInt(c.GetAttrib ("bet")) * 5
NEXT I 'thus repeats 5 times
NEXT I

But one might question the soundness of why you'd want this in the first place, but there you go. (as an aside to David: I'm going for tab indentation, you can see windows has set that to 6 spaces, but I'm addicted to emacs style tab indentation)
Cheers,
Mich


Michiel Spapé
Research Fellow
Perception & Action group
University of Nottingham
School of Psychology
www.cognitology.eu

Hello

Example:

*repeat 5 times

*repeat 5 times

END IF

--
You received this message because you are subscribed to the Google Groups "E-Prime" group.
To post to this group, send email to e-p...@googlegroups.com.
To unsubscribe from this group, send email to e-prime+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/e-prime?hl=en.

This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

jens

unread,
Jan 12, 2011, 6:57:55 AM1/12/11
to E-Prime
Thank you very much, it works perfect.


"...one might question the soundness of why you'd want this in the
first place..."

Yes one can. I'm using this to toggle an electrical stimulator on and
off using different segment widths for different situations.


Best,
Jens
Reply all
Reply to author
Forward
0 new messages