Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Why? A Bug? What have I missed?
Author | Message | ||||
Nixie Regular Member Joined: 19/02/2013 Location: AustraliaPosts: 66 |
Greetings all. Have not been on for a while... Travelling... Can someone tell me why this happens...please (using a B/W MM with 4.3a MMBASIC) 10 CLS 20 Input "Hours ";H 30 IF H=12 THEN ST=18:IF H=13 THEN ST=68:IF H=14 THEN ST=127 40 PRINT H,ST If I enter 12, the result at line 40 is 12 18 If I enter 13, I get 13 0 If I enter 14, I get 14 0 However, if I enter each of the segments in line 30 on a separate line; then I get the correct results 13 68 And 14 127 respectively Many thanks, Nic |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
Everything after IF H=12 THEN will only be executed when H = 12 IF H=13 and the IF H=14 will never be true because that code is only reached when H = 12 Microblocks. Build with logic. |
||||
Nixie Regular Member Joined: 19/02/2013 Location: AustraliaPosts: 66 |
Ah! Thankyou! Thankyou! Think my logic is skiwiff! Cheers, Nic |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
Yes, it is a peculiarity of BASIC that everything on the line after the THEN is skipped if the test is false (this is documented in the manual). Geoff Geoff Graham - http://geoffg.net |
||||
Print this page |