The if .. then statement
tore eilertsen
Posts: 15
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
·
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
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
Thank You ... that helped a lot·
tore
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