![]() |
Forum Index : Microcontroller and PC projects : MMBasic valid criteria
Author | Message | ||||
OA47 Guru ![]() Joined: 11/04/2012 Location: AustraliaPosts: 986 |
Is this type of expression valid in MMBasic: IF 0 <= Variable <= 10 Then ????????????? OA47 |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
No If you try you will get caught up in comparing the result of a comparison with the other value/expression. If (0 <= variable) and (variable <= 10) I am not sure if the brackets are required. I did experiment with that some time ago. Too many electrons flowed under the bridge since then... You could do a function if there are a few to do, Jim VK7JH MMedit |
||||
OA47 Guru ![]() Joined: 11/04/2012 Location: AustraliaPosts: 986 |
Thanks Jim. The program was accepting the code (I am not sure which variation of Basic I got it from) but I was getting unpredictable outcomes. Merry Christmas OA47 |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
select/case might be a fit for you - it has a close enough syntax to what you give above: Select Case x Case 0 To 10 ... End Select bit long-winded if you are doing just a single comparison tho' also, consider Constrain(), that might fit what you are doing. h |
||||
toml_12953 Guru ![]() Joined: 13/02/2015 Location: United StatesPosts: 442 |
In many BASICs, the first part (0 <= Variable) will return a -1 if variable >=0 and a 0 if variable <0. Then it will compare that result with 10. Since both 0 and -1 are <=10 the branch will always be taken Edited 2022-12-23 01:20 by toml_12953 |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |