![]() |
Forum Index : Microcontroller and PC projects : Compare Bugs ?
Author | Message | ||||
georgestheking Newbie ![]() Joined: 21/12/2021 Location: BelgiumPosts: 32 |
I try to check if a number is ODD or EVEN using PICOMITE 5.07.01 dim integer I,P dim float F for P=0 to 15 I=P/2 F=P/2 if I=F then print "ODD" else print "EVEN" endif next I get always ODD ! What is wrong ? Thanks for your help Georges Edited 2021-12-21 17:35 by georgestheking |
||||
georgestheking Newbie ![]() Joined: 21/12/2021 Location: BelgiumPosts: 32 |
After a lot of testing I found that this version is working dim integer I,P dim float F for P=0 to 15 I=P/2 F=P/2 if I=F then print "ODD" else print "EVEN" endif next |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2640 |
An observation. On an F4 I get this:- > for p%=0 to 15 :i%=p%/2 : f=p%/2 : if f=i% then : print "odd" : else : ? "even" :endif : next odd even odd even odd even odd even odd even odd even odd even odd even > But on a Pico this:- > for p%=0 to 15 :i%=p%/2 : f=p%/2 : if f=i% then : print "odd" : else : ? "even" :endif : next Error : Cannot find a matching FOR > Same sort of error if I try a Do...Loop Until - no matching Do Pico not quite the same as the rest in Immediate Mode. No loops it seems. |
||||
CaptainBoing![]() Guru ![]() Joined: 07/09/2016 Location: United KingdomPosts: 2170 |
The close of the loop is only being executed as part of the If. Strange that it is not being picked up in both versions. as to the original inquiry; for integers you can use a bitwise AND (very fast, and a bit faster still if you specify the radix): ... If (P And &h1) Then 'odd ... for (whole number) floats you can say ... If (P/2)<>Int(p/2) Then 'odd ... which is pretty much what you were doing anyway but avoids mixing datatypes (here be dragons). Edited 2021-12-21 18:38 by CaptainBoing |
||||
georgestheking Newbie ![]() Joined: 21/12/2021 Location: BelgiumPosts: 32 |
Nice Tricks Captain, Thanks, |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
That's perfectly correct. IF test THEN process is an abbreviation that can be on a single line only because there are no alternatives. Unabbreviated it would be IF test THEN process if passed END IF the correct form of the command with an alternative is IF test THEN process if passed ELSE process if failed END IF Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
wolfme Newbie ![]() Joined: 26/10/2021 Location: GermanyPosts: 31 |
Another way (and in one line): For r%=0 To 15 : If r% Mod 2 Then Print "odd" Else Print "even" : Next r% your code from above should be like this on pico: For p%=0 To 15 :i%=p%/2 : f=p%/2 : If f=i% Then Print "odd" Else Print "even" : Next EDIT: it seems that your code from above ist wrong, it prints the opposite (1 is even, 2 is odd and so on) Edited 2021-12-21 19:08 by wolfme |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2640 |
"Pico not quite the same as the rest in Immediate Mode. No loops it seems." Found the problem. Line length too long, despite all characters showing on the screen some were being lost. Using OPTION DISPLAY 50,120 fixed it. |
||||
wolfme Newbie ![]() Joined: 26/10/2021 Location: GermanyPosts: 31 |
aaah, ok. You typed in to command line. I always use option display 50,132 thats maximum i think. |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
This is interesting. I've encountered this error, but never figured out the reason, so thank you. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
> dim integer P for P=0 to 15 if p mod 2 then print p,"ODD" else print p ,"EVEN" endif next p RUN 0 EVEN 1 ODD 2 EVEN 3 ODD 4 EVEN 5 ODD 6 EVEN 7 ODD 8 EVEN 9 ODD 10 EVEN 11 ODD 12 EVEN 13 ODD 14 EVEN 15 ODD > Jim VK7JH MMedit |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |