Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 19:40 27 Nov 2024 Privacy Policy
Jump to

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: Australia
Posts: 66
Posted: 12:44am 03 Jun 2013
Copy link to clipboard 
Print this post

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: Thailand
Posts: 2209
Posted: 12:58am 03 Jun 2013
Copy link to clipboard 
Print this post

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: Australia
Posts: 66
Posted: 01:23am 03 Jun 2013
Copy link to clipboard 
Print this post

Ah! Thankyou! Thankyou!
Think my logic is skiwiff!
Cheers, Nic
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 02:39am 03 Jun 2013
Copy link to clipboard 
Print this post

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


To reply to this topic, you need to log in.

© JAQ Software 2024