Shop OBEX P1 Docs P2 Docs Learn Events
Pulsin in a if then statment — Parallax Forums

Pulsin in a if then statment

ArchiverArchiver Posts: 46,084
edited 2004-01-20 16:15 in General Discussion
Hi all
Is it ok to do this as a statement line... i.e. the
IF x>=3 AND x<=4 OR x=0 THEN
PULSIN 0,0,x
ENDIF
in below part of a program
on
'{$STAMP BS2}
'{$PBASIC 2.5}

SAMPLE2:
PULSIN 0,0,x
IF x>=3 AND x<=4 OR x=0 THEN
PULSIN 0,0,x ............................................ The reason I am
checking twice is if i get a consistent 3 or 4 or 0 I know sequence has ended .
want to move on rather than sample again.
ENDIF
IF x>=3 AND x<=4 OR x=0 THEN DISPLAYA
CHK(0) = x
I=1
FOR I=1 TO 8
PULSIN 0,0,x
CHK(I)=x
NEXT
GOTO CHECKCOUNT2 (do some maths here at checkcount two with results)

The reason I am checking twice is if i get a consistent 3 or 4 or 0 I know
sequence has ended and want to move on rather than sample again.
Used x>=3 AND x<=4 as may swap to a variable later like x>=A AND x<=B

Also another question on variables in a FOR NEXT loop

PROGRAMBODYC:
N=0 ...................................... (as I am using the same variable N
and M in different programbodya:,b ,c, d is it correct to set them to 0 for a
FOR N=0 TO 4 loop)
M=0 .......................................(so as not to get an error on the
FOR NEXT loop in next part of program)
FOR N=0 TO 4
M=(8-N)
IF CHK(N)>CHK(M) THEN
LC=LC+1
ENDIF
IF CHK(N)<CHK(M) THEN
HC=HC+1
ENDIF
NEXT
GOTO SAMPLE3

Its on a BS2 and all the variables are defined at the top!

I have use this a couple of times (PROGRAMBODYC: and SAMPLE2: re named D and 3
etc respectively) in the same program it seems to work the first two times but
not sure if its working properly over. Cant DEBUG to a screen without a big
effort.

Thanks in advance



Rob Farrand

This email is confidential and may also be privilege.
If you are not the intended recipient, please notify us immediately.
You should not copy or use it for any purpose, nor disclose it's contents to any
other person.



[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-01-20 07:07
    At 02:29 PM 1/20/04 +1030, Rob Farrand ... FTech Connection wrote:
    >Hi all
    >Is it ok to do this as a statement line... i.e. the
    >IF x>=3 AND x<=4 OR x=0 THEN
    >PULSIN 0,0,x
    >ENDIF

    The Stamp only recognizes integers, so the beginning of that IF statement has no
    logical meaning, and can only be TRUE when X=0.

    >in below part of a program
    >on
    >'{$STAMP BS2}
    >'{$PBASIC 2.5}
    >
    >SAMPLE2:
    >PULSIN 0,0,x
    >IF x>=3 AND x<=4 OR x=0 THEN
    >PULSIN 0,0,x ............................................ The reason I am
    checking twice is if i get a consistent 3 or 4 or 0 I know sequence has ended .
    want to move on rather than sample again.
    >ENDIF
    >IF x>=3 AND x<=4 OR x=0 THEN DISPLAYA
    >CHK(0) = x
    >I=1
    >FOR I=1 TO 8
    >PULSIN 0,0,x
    > CHK(I)=x
    >NEXT
    >GOTO CHECKCOUNT2 (do some maths here at checkcount two with results)
    >
    >The reason I am checking twice is if i get a consistent 3 or 4 or 0 I know
    sequence has ended and want to move on rather than sample again.
    >Used x>=3 AND x<=4 as may swap to a variable later like x>=A AND x<=B
    >
    >Also another question on variables in a FOR NEXT loop
    >
    >PROGRAMBODYC:
    >N=0 ...................................... (as I am using the same variable N
    and M in different programbodya:,b ,c, d is it correct to set them to 0 for a
    FOR N=0 TO 4 loop)
    >M=0 .......................................(so as not to get an error on the
    FOR NEXT loop in next part of program)

    It will be set to ZERO at the beginning of the loop, so it really isn't
    necessary.

    >FOR N=0 TO 4
    >M=(8-N)
    >IF CHK(N)>CHK(M) THEN
    >LC=LC+1
    >ENDIF
    >IF CHK(N)<CHK(M) THEN
    >HC=HC+1
    >ENDIF
    >NEXT
    >GOTO SAMPLE3
    >
    >Its on a BS2 and all the variables are defined at the top!
    >
    >I have use this a couple of times (PROGRAMBODYC: and SAMPLE2: re named D and 3
    etc respectively) in the same program it seems to work the first two times but
    not sure if its working properly over. Cant DEBUG to a screen without a big
    effort.
    >
    >Thanks in advance
    >
    >Rob Farrand
    Regards,

    Bruce Bates


    >
    >This email is confidential and may also be privilege.
    >If you are not the intended recipient, please notify us immediately.
    >You should not copy or use it for any purpose, nor disclose it's contents to
    any other person.
    >
    >
    >
    >[noparse][[/noparse]Non-text portions of this message have been removed]
    >
    >
    >To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    >from the same email address that you subscribed. Text in the Subject and Body
    of the message will be ignored.
    >
    >
    >Yahoo! Groups Links
    >
    >To visit your group on the web, go to:
    > http://groups.yahoo.com/group/basicstamps/
    >
    >To unsubscribe from this group, send an email to:
    > basicstamps-unsubscribe@yahoogroups.com
    >
    >Your use of Yahoo! Groups is subject to:
    > http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2004-01-20 16:15
    Yes, you can do this, but you should be
    aware that PBasic evaluates strictly from
    left to right -- UNLESS you use parens to
    detail your intent. So it should be:
    IF ( ( X >= 3) AND (X <= 4) ) OR (X = 0) THEN

    Note this 'strict left-to-right' evaluation
    is NOT typical of programming languages, but
    simplifies the PBasic runtime, with the only
    cost being the additional parens.

    --- In basicstamps@yahoogroups.com, "Rob Farrand ... FTech
    Connection" <ftech@n...> wrote:
    > Hi all
    > Is it ok to do this as a statement line... i.e. the
    > IF x>=3 AND x<=4 OR x=0 THEN
    > PULSIN 0,0,x
    > ENDIF
    > in below part of a program
    > on
    > '{$STAMP BS2}
    > '{$PBASIC 2.5}
    >
    > SAMPLE2:
    > PULSIN 0,0,x
    > IF x>=3 AND x<=4 OR x=0 THEN
    > PULSIN 0,0,x ............................................ The
    reason I am checking twice is if i get a consistent 3 or 4 or 0 I
    know sequence has ended . want to move on rather than sample again.
    > ENDIF
    > IF x>=3 AND x<=4 OR x=0 THEN DISPLAYA
    > CHK(0) = x
    > I=1
    > FOR I=1 TO 8
    > PULSIN 0,0,x
    > CHK(I)=x
    > NEXT
    > GOTO CHECKCOUNT2 (do some maths here at checkcount two with results)
    >
    > The reason I am checking twice is if i get a consistent 3 or 4 or 0
    I know sequence has ended and want to move on rather than sample
    again.
    > Used x>=3 AND x<=4 as may swap to a variable later like x>=A AND
    x<=B
    >
    > Also another question on variables in a FOR NEXT loop
    >
    > PROGRAMBODYC:
    > N=0 ...................................... (as I am using the
    same variable N and M in different programbodya:,b ,c, d is it
    correct to set them to 0 for a FOR N=0 TO 4 loop)
    > M=0 .......................................(so as not to get an
    error on the FOR NEXT loop in next part of program)
    > FOR N=0 TO 4
    > M=(8-N)
    > IF CHK(N)>CHK(M) THEN
    > LC=LC+1
    > ENDIF
    > IF CHK(N)<CHK(M) THEN
    > HC=HC+1
    > ENDIF
    > NEXT
    > GOTO SAMPLE3
    >
    > Its on a BS2 and all the variables are defined at the top!
    >
    > I have use this a couple of times (PROGRAMBODYC: and SAMPLE2: re
    named D and 3 etc respectively) in the same program it seems to work
    the first two times but not sure if its working properly over. Cant
    DEBUG to a screen without a big effort.
    >
    > Thanks in advance
    >
    >
    >
    > Rob Farrand
    >
    > This email is confidential and may also be privilege.
    > If you are not the intended recipient, please notify us
    immediately.
    > You should not copy or use it for any purpose, nor disclose it's
    contents to any other person.
    >
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.