Shop OBEX P1 Docs P2 Docs Learn Events
The if .. then statement — Parallax Forums

The if .. then statement

tore eilertsentore eilertsen Posts: 15
edited 2008-03-14 18:10 in BASIC Stamp
Hi..

Is it possibel to use·· IF A = B then C=1···· (example)..
or must the if then· always point to a subroutine, if so· can the IF A statment be done in any
other way


tore


·

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2008-03-14 12:59
    The one line "IF" statement does a GOTO.

    However, you DO have a 'multi-line' IF-THEN statement in the BS2, and that will let you do:
    IF A = B THEN
    C = 1
    ENDIF

    And, in PBasic, a colon ":" lets you put multi-line statements on the same line, so you could do:

    IF A = B THEN: C = 1: ENDIF
  • tore eilertsentore eilertsen Posts: 15
    edited 2008-03-14 14:14
    Hi..



    Thank You ... that helped a lot· icon6.gif

    tore
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2008-03-14 18:10
    Simply this:

    IF A=B THEN C=1

    will work fine, but you have to choose PBASIC 2.5. See the icon in the menu bar, or menu option, or put in the comment
    ' {$PBASIC 2.5}
    at the head of the program. That syntax does not work in earlier versions of the compiler, which may be why you asked the question.

    Another tricky way to do that particular operation with math is,

    C = 1 - (A - B MAX 1) ' C=1 iff A=B

    but that is slower and takes more code. In some cases that approach is effective.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.