I'm looking for a S*BASIC app, possibly by Tim Swenson!

Anything QL Software or Programming Related.
User avatar
NormanDunbar
Forum Moderator
Posts: 2464
Joined: Tue Dec 14, 2010 9:04 am
Location: Buckie, Scotland
Contact:

Re: I'm looking for a S*BASIC app, possibly by Tim Swenson!

Post by NormanDunbar »

Morning all,

attached are the sources and executable for SSB version 2.7.2d which has had the Spanish language added as per the previous post from @badaman.

The zip file was created on a QL, not on a Linux/Windows/Mac device. ;)


ssb272d.zip
(48.87 KiB) Downloaded 199 times


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Derek_Stewart
Font of All Knowledge
Posts: 4663
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: I'm looking for a S*BASIC app, possibly by Tim Swenson!

Post by Derek_Stewart »

Hi

The updated to SSB look great.

Looking at the source code I noticed the all the FOR loops are terminated with a NEXT statement and not an ENF FOR statement.

Just re-read The SuperBasic Handbook by Jan Jones where she says the NEXT statement can terminate a loop.

Code: Select all

200 REPeat gobbledegook
210     a$ = CHR$(RND(65 TO 90))
220     PRINT a$;
230     IF a$=”A”: min=min+1: NEXT gobbledegook
240     IF a$=”Z”: max=max+1
250     NEXT gobbledegook

Which I have never used NEXT to terminate a REPeat loop.

The examples on the book have END FOR to terminate the FOR loop block.

But Jan quotes an example of a FOR loop with the NEXT statement to control the loop and the END FOR statement to mark the end the FOR construct:

Code: Select all

330 FOR k = 0 TO DIMN(arr$,1)
340     row = k: IF arr$(row)==name$:EXIT k
350     NEXT k
360     row = -1
370 END FOR k
What is the best way, or does this not matter?


Regards,

Derek
User avatar
tofro
Font of All Knowledge
Posts: 3071
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: I'm looking for a S*BASIC app, possibly by Tim Swenson!

Post by tofro »

Yes, you can use NEXT in a REPeat loop to start the next iteration prematurely (typically conditionally).

And yes, you can use NEXT to end a FOR loop - The distinction between NEXT and END FOR is more or less syntactic sugar (The proper way is In theory, to use NEXT to restart the loop prematurely (i.e., with an IF condition, typically) and use END FOR for the loop's outer termination. The interpreter will be happy with both. Turbo will complain with a warning if it finds FOR loops that are not terminated with END FOR but NEXT, however (and educate you you meant END FOR).

I personally find it a lot clearer when the outer termination is done with END FOR, and a conditional restart is done with NEXT (i.e., the intended way). That's just a lot easier to read.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
swensont
Forum Moderator
Posts: 323
Joined: Tue Dec 06, 2011 3:30 am
Location: SF Bay Area
Contact:

Re: I'm looking for a S*BASIC app, possibly by Tim Swenson!

Post by swensont »

Norman,

Thanks for picking up the torch on SSB and releasing a new version. Still nice to see others interested in SSB.

The reason for "FOR...NEXT" instead of "FOR...END FOR" is mostly due to "FOR...NEXT" being the original BASIC syntax and SuperBASIC added a new option but did not remove the original syntax.

Tim


User avatar
BSJR
Trump Card
Posts: 220
Joined: Sun Oct 18, 2015 12:53 pm
Location: Amsterdam
Contact:

Re: I'm looking for a S*BASIC app, possibly by Tim Swenson!

Post by BSJR »

tofro wrote: Fri Jul 05, 2024 3:43 pm Yes, you can use NEXT in a REPeat loop to start the next iteration prematurely (typically conditionally).
...
There can be a small difference in use.
The NEXT will update the FOR variable, find it's out of range and terminate the loop.
The END FOR will not do that.
If you do test this variable outside the loop that must be considered.

BSJR


User avatar
tofro
Font of All Knowledge
Posts: 3071
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: I'm looking for a S*BASIC app, possibly by Tim Swenson!

Post by tofro »

BSJR wrote: Sat Jul 06, 2024 11:26 am
tofro wrote: Fri Jul 05, 2024 3:43 pm Yes, you can use NEXT in a REPeat loop to start the next iteration prematurely (typically conditionally).
...
There can be a small difference in use.
The NEXT will update the FOR variable, find it's out of range and terminate the loop.
The END FOR will not do that.
If you do test this variable outside the loop that must be considered.

BSJR
Right, forgot that, thanks. Probably because I never check for loop variables outside the loop - I find that's a bad practice.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
pjw
QL Wafer Drive
Posts: 1608
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: I'm looking for a S*BASIC app, possibly by Tim Swenson!

Post by pjw »

Just remember this little trap for the unwary:

Code: Select all

100 CLS
102 FOR i = 1 TO 7
104  i = 8: NEXT i
106  PRINT 'Uh oh'
108 END FOR i
110 :
This behaviour is probably more like what was expected

Code: Select all

100 CLS
102 FOR i = 1 TO 7
104  i = 8: NEXT i: PRINT 'ok': EXIT i
106  PRINT 'Uh oh'
108 END FOR i


Per
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
User avatar
NormanDunbar
Forum Moderator
Posts: 2464
Joined: Tue Dec 14, 2010 9:04 am
Location: Buckie, Scotland
Contact:

Re: I'm looking for a S*BASIC app, possibly by Tim Swenson!

Post by NormanDunbar »

swensont wrote: Fri Jul 05, 2024 10:57 pm Norman,

Thanks for picking up the torch on SSB and releasing a new version. Still nice to see others interested in SSB.
Hi Tim, no problem. I was a bit worried that you might object! I was wondering if you would have any objections to putting the source up on the Sinclair QL GitHub?

If you have no objections to me doing so, I'll get it sorted. I can do different releases for the different versions from 2.7.2 as well, in case anyone needs those specific ones.

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Martin_Head
Aurora
Posts: 967
Joined: Tue Dec 17, 2013 1:17 pm

Re: I'm looking for a S*BASIC app, possibly by Tim Swenson!

Post by Martin_Head »

Derek_Stewart wrote: Fri Jul 05, 2024 2:24 pm
But Jan quotes an example of a FOR loop with the NEXT statement to control the loop and the END FOR statement to mark the end the FOR construct:

Code: Select all

330 FOR k = 0 TO DIMN(arr$,1)
340     row = k: IF arr$(row)==name$:EXIT k
350     NEXT k
360     row = -1
370 END FOR k
What is the best way, or does this not matter?
The Concepts section of the QL User Manual, under repetition. Says that the code between the NEXT and the END FOR, is a loop epilogue, that is only executed if the FOR range is exhausted.

So in the above example. After the END FOR k, row is the array index if name$ was found, or -1 if it was not (loop exhausted). Line 360 is only executed if k=DIMN(arr$,1).


swensont
Forum Moderator
Posts: 323
Joined: Tue Dec 06, 2011 3:30 am
Location: SF Bay Area
Contact:

Re: I'm looking for a S*BASIC app, possibly by Tim Swenson!

Post by swensont »

Norman said: "I was wondering if you would have any objections to putting the source up on the Sinclair QL GitHub?"

I have no issue with that. I'm not planning on doing any further work on SSB. It has all the features that I need (and them some).

Tim


Post Reply