gaslouk
Full Member
Hi from beautiful Greece.
Posts: 130
|
Post by gaslouk on Jan 27, 2023 0:48:40 GMT -5
Hello.
I would like to ask about the use of the "if...Then" command when after using, "if cancelOpp=1 then cancelOpp=0: wait" if the condition is not true does it continue after the resolvers to read the "wait" command? If it does not read it when the condition is not false, what other peculiarities does the command have? The more examples you give me the better it will be for me. Many thanks to the team in advance for this and other questions I will ask in the future.
|
|
|
Post by tsh73 on Jan 27, 2023 3:32:02 GMT -5
no Just change "wait" to "print 1" etc and see for yourself
*this* is not "peculiarities" It really works as it should.
(but IF in LB indeed has a fiew quirks)
Normal operation
'do something if condition is met if condition then someOperation 'or you can do several operations if condition then someOperation1: someOperation2: someOperation3
'full form: if condition is met, other then it is not if condition then someOperation else someOtherOperation 'or you can do several operations if condition then someOperation1: someOperation2: someOperation3 else someOtherOperation1: someOtherOperation2
'gotcha: 'now, I myself would NOT put line IF inside line IF for the sake of my sanity
'block form if condition then someOperation end if
'Gotcha: indents are only for good look, not affect code execution
'nested - someOperation could be another IF
if x>0 then if y >1 then print "I" else print "II" end if else if y >1 then print "VI" else print "III" end if end if
if condition then 'really any number of operations someOperation1 someOperation2 someOperation3 end if 'with ELSE part
if condition then someOperation else someOtherOperation end if
if condition then someOperation1 someOperation2 someOperation3 else someOtherOperation1 someOtherOperation2 end if
Quirks I'm aware of: non-integer value as condition possibly evaluates wrong (or not as I expect it) (or probably fail with error)
x =1 if x then print "True" else print "false" x =0 if x then print "True" else print "false"
'now I remember it could fail (runtime error) if x is not integer 'check for yourself. Should it print True or False? x =0.1 if x then print "True" else print "false"
AND OR does not respect operator precedence
if 1 and 1 or 1 and 0 then print "True" else print "False" 'should work "AND" first, as if (1 and 1) or (1 and 0) then print "True" else print "False"
|
|
|
Post by tsh73 on Jan 27, 2023 4:16:03 GMT -5
Also "chaining" conditions - check first one, if not holds then second one, ... This approach DOES NOT WORK
if cond1 then print "action 1" else if cond2 then print "action 2" else if cond3 then print "action 3" else print "action ELSE" end if
You can nest IF conditions, each with own END IF (as I said, indents are only for look) But it will require many END IFs
if cond1 then print "action 1" else if cond2 then print "action 2" else if cond3 then print "action 3" else print "action ELSE" end if end if end if
Or could use SELECT CASE - it's rather powerful in LB (and I think a bit different from QBasic)
select case case cond1 print "action 1" case cond2 print "action 2" case cond3 print "action 3" case else print "action ELSE" end select
|
|
gaslouk
Full Member
Hi from beautiful Greece.
Posts: 130
|
Post by gaslouk on Jan 27, 2023 7:34:11 GMT -5
|
|