Suggestion: Do/Loop/While/Until/exit

If you have feature requests, this is the place to post them. Please note your idea may already be something we have already discussed and decided against, or something we are working on privately, and we cannot be held responsible for any similarities in such instance. Whilst we cannot respond to every suggestion, your idea will be read and responded to where possible. Thank you for your input!
Post Reply
Desert-Fox
Posts: 1
Joined: Thu Apr 18, 2024 8:46 pm

General - CX16 Suggestion: Do/Loop/While/Until/exit

Post by Desert-Fox »

I hope this hasn't been brought up previously. I looked but could not find anything.

Would it be possible to add DO/LOOP/WHILE/UNTIL/EXIT to the current BASIC for the X16?
I had it in BASIC 7.0 on the C128 and was hoping it might be included here.
TomXP411
Posts: 1781
Joined: Tue May 19, 2020 8:49 pm

Re: Suggestion: Do/Loop/While/Until/exit

Post by TomXP411 »

Honestly, I think the team is done adding new BASIC commands. While DO loops are handy, they don't actually add functionality that can't be achieved with an IF/GOTO.

We've had some discussion on the Discord, and I've even started working on a P-Code engine, but then David dropped the 65C816 and "look! A serial card!" bombs on us, and we all kind of pivoted to that.

At some point, there will be a BASIC compiler, and that's where new language features will be added.


In the meantime, it's fairly straightforward to convert DO and WHILE loops to IF/GOTO loops:

Here's a WHILE loop in line numbered BASIC:

100 WHILE condition 110 do stuff 120 do more stuff 130 LOOP

Here's the IF/GOTO version:
100 GOTO 130 110 do stuff 120 do more stuff 130 IF condition GOTO 110

and the BASLOAD version:

GOTO L2 L1: do stuff do more stuff L2: IF condition THEN L1

To convert a DO loop, just leave out the first GOTO. Otherwise, it's the same.
mgkaiser
Posts: 60
Joined: Sat Dec 02, 2023 6:49 pm

Re: Suggestion: Do/Loop/While/Until/exit

Post by mgkaiser »

Maybe add them to BASLOAD and let it implement them with existing BASIC 2.0 commands. Other "syntactic sugar" like SELECT CASE and multi line IF...THEN could also be implemented. Maybe even SUB and FUNCTION? Yes, FUNCTION is a stretch...
DragWx
Posts: 340
Joined: Tue Mar 07, 2023 9:07 pm

Re: Suggestion: Do/Loop/While/Until/exit

Post by DragWx »

This sounds like BASIC++, like what C++ is to C. :D

In other words, totally doable, but maybe better suited to one of the IDEs that's baked into the ROM.
User avatar
ahenry3068
Posts: 1131
Joined: Tue Apr 04, 2023 9:57 pm

Re: Suggestion: Do/Loop/While/Until/exit

Post by ahenry3068 »

mgkaiser wrote: Fri Apr 19, 2024 2:49 am Maybe add them to BASLOAD and let it implement them with existing BASIC 2.0 commands. Other "syntactic sugar" like SELECT CASE and multi line IF...THEN could also be implemented. Maybe even SUB and FUNCTION? Yes, FUNCTION is a stretch...
FUNCTION Might be easier than SELECT CASE. If it was me, Function would translate as so.

Create a New Var with the same Name as FUNCTION

FUNCTION FirstLetter(X$):
FirstLetter=LEFT(X$,1)
RETURN


B=FirstLetter("Hello")


Translates to:

FirstLetterP1$="Hello"
GOSUB Function


FirstLetter:
B=LEFT$(FirstLetterP1$,1)
RETURN

FirstLetterP1$="Hello"
GOSUB FirstLetter
B=FirstLetter$
BruceRMcF
Posts: 224
Joined: Sat Jan 07, 2023 10:33 pm

Re: Suggestion: Do/Loop/While/Until/exit

Post by BruceRMcF »

The real benefits of having them in RomBASIC is that they can be made to be more efficient, like FOR / NEXT, because you can stack information on a structure stack to be completed by the end of the structure and avoid scanning through the program for the target line as with GOTO.

But BASLOAD implenting structures with IF/THEN and GOTO and then providing a Blitz-style p-code compiler for the RomBASIC code provides that benefit at the point of doing the p-code compilation, which substantially reduces the benefit of adding it to RomBASIC.

This is similar to the discussions from a couple of years back of adding integer arithmetic to expressions which are presently converting integers to floats for evaluation and then converting back to integers ... the real bang for the buck in that upgrade is not in RomBASIC, it's adding that as a refinement to the Blitz compiler.
mgkaiser
Posts: 60
Joined: Sat Dec 02, 2023 6:49 pm

Re: Suggestion: Do/Loop/While/Until/exit

Post by mgkaiser »

ahenry3068 wrote: Fri Apr 19, 2024 7:13 am
mgkaiser wrote: Fri Apr 19, 2024 2:49 am Maybe add them to BASLOAD and let it implement them with existing BASIC 2.0 commands. Other "syntactic sugar" like SELECT CASE and multi line IF...THEN could also be implemented. Maybe even SUB and FUNCTION? Yes, FUNCTION is a stretch...
FUNCTION Might be easier than SELECT CASE. If it was me, Function would translate as so.

Create a New Var with the same Name as FUNCTION

FUNCTION FirstLetter(X$):
FirstLetter=LEFT(X$,1)
RETURN


B=FirstLetter("Hello")


Translates to:

FirstLetterP1$="Hello"
GOSUB Function


FirstLetter:
B=LEFT$(FirstLetterP1$,1)
RETURN

FirstLetterP1$="Hello"
GOSUB FirstLetter
B=FirstLetter$
Nice! That is very flexible!
User avatar
ahenry3068
Posts: 1131
Joined: Tue Apr 04, 2023 9:57 pm

Re: Suggestion: Do/Loop/While/Until/exit

Post by ahenry3068 »

mgkaiser wrote: Sat Apr 20, 2024 12:43 am
ahenry3068 wrote: Fri Apr 19, 2024 7:13 am
mgkaiser wrote: Fri Apr 19, 2024 2:49 am Maybe add them to BASLOAD and let it implement them with existing BASIC 2.0 commands. Other "syntactic sugar" like SELECT CASE and multi line IF...THEN could also be implemented. Maybe even SUB and FUNCTION? Yes, FUNCTION is a stretch...
FUNCTION Might be easier than SELECT CASE. If it was me, Function would translate as so.

Create a New Var with the same Name as FUNCTION

FUNCTION FirstLetter(X$):
FirstLetter=LEFT(X$,1)
RETURN


B=FirstLetter("Hello")


Translates to:

FirstLetterP1$="Hello"
GOSUB Function


FirstLetter:
B=LEFT$(FirstLetterP1$,1)
RETURN

FirstLetterP1$="Hello"
GOSUB FirstLetter
B=FirstLetter$
Nice! That is very flexible!
This is pretty much the approach I'm taking manually to translate some Qbasic code to BASLOAD where the QBASIC code uses

FUNCTION END FUNCTION
Post Reply