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 : Dec Command missing
Author | Message | ||||
Archimedes5000 Newbie Joined: 21/01/2021 Location: GermanyPosts: 6 |
CMM2 V5.06 It doesn't matter that much, but I found the INC command and then searched for DEC as well. Doesn't he seem to be there? Possibly to be taken into account in a future firmware? Greetings Axel |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 5705 |
"INC x,-1" is the way to do it. The value can be positive or negative so you can DEC by 5 using "INC x,-5" etc. It looks a little odd but it's flexible, it works and it only needs one entry in the commands table. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
jirsoft Guru Joined: 18/09/2020 Location: Czech RepublicPosts: 532 |
The advantage is you can use it without IF condition: INC variable, step*(variable < upperLimit) INC variable, -step*(variable > lowerLimit) INC i,(i<10) will for example add 1 to i but maximal up to 10 Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 3496 |
why INC ? i=i+(i<10) PicomiteVGA PETSCII ROBOTS |
||||
jirsoft Guru Joined: 18/09/2020 Location: Czech RepublicPosts: 532 |
If I understood it correctly, INC should be faster... If correctly programmed, after evaluation of right side to 0 nothing happens. In your case will be still i=i Edited 2021-04-07 21:04 by jirsoft Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), CMM2.fun |
||||
Tinine Guru Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
Very cool |
||||
RetroJoe Senior Member Joined: 06/08/2020 Location: CanadaPosts: 290 |
There was a thread on INC when Peter first introduced it. It is intended to accelerate simple increments and decrements for counter variables, as the interpreter knows to take a more direct evaluation path versus parsing a generic algebraic expression. It is measurably faster, but I agree with the semantic purists on this - "incrementing" by a negative number is counterintuitive, and the "missing" DEC command makes the language less orthogonal and readable. I expect Peter made this decision to save a few bytes somewhere, but creeping inelegance is a slippery syntactical slope. Put another way, "symmetry is beauty". Edited 2021-04-08 02:01 by RetroJoe Enjoy Every Sandwich / Joe P. |
||||
Print this page |