Christmas Fun

Anything QL Software or Programming Related.
stevepoole
Aurora
Posts: 896
Joined: Mon Nov 24, 2014 2:03 pm

Re: Christmas Fun

Post by stevepoole »

Hi Folks,
Just been reading the TURBO manual, section 2,6,3 : WARNINGS & Auto-Corrections :

Tubro says : always prefer END FOR instead of NEXT, (the latterof which should only be used for 'loop epilogues').

NEXT was only included in SuperBasic for a 'degree' of compatibility with other Basics.

NEXT is too powerful : It can jump out of a subroutine or other loop2 and back out to a Global loop1. (try it! it can be useful here).

Used within an IF.......NEXT statement, it is best replaced by an IF.....GOTO ('END FOR ' line_number).

Be careful with NEXT....... Regards, Steve.


User avatar
Andrew
QL Wafer Drive
Posts: 1047
Joined: Tue Jul 17, 2018 9:10 pm

Re: Christmas Fun

Post by Andrew »

dilwyn wrote: Mon Dec 19, 2022 11:32 pm
It looks like when the specific case of 2 or more nested FOR/NEXT loops terminated with NEXT are used inline (i.e. not in a PROC/FN) *and* there is a procedure or function, then the outermost NEXT of the nested inline FOR loops must be changed to a END FOR. It doesn't matter if the loop control variable is a float or integer. Possibly Turbo is not keeping track of nested NEXTs correctly, possibly a 1 to n versus 0 to n-1 count error within Turbo in keeping track of labels. I admit I have no idea why the nested loops compile correctly if there are no procedures, but stop compiling correctly when there is a procedure!

I quickly tried it on JS ROM in QemuLator to check it wasn't something specific to SBASIC. Apart from the fact that SuperBASIC doesn't allow integer loop variables (just change c% and d% to c and d in the example), the same problem occurs, so it is specific to Turbo, and not some form of tokenisation error in S*BASIC for example.

Not quite sure why my earlier attempts meant I had to SAVE and reLOAD the program for it to work - it's possible there's something else in there which Turbo doesn't like.
Thank you Dilwyn - this clears the mistery!

I have tried before to use END FORs as Martyn_Hill suggested in a previous message, but I have not saved and reloaded the program and the compiling failed.


User avatar
dilwyn
Mr QL
Posts: 3126
Joined: Wed Dec 01, 2010 10:39 pm

Re: Christmas Fun

Post by dilwyn »

I suspect that Steve is right, that basically if we stick to the script of using FOR / END FOR in QL style instead of FOR / NEXT Spectrum style we are protecting ourselves from this condition.
By following what Andrew had said he'd already tried, a clue was in the Turbo report file, something like Warning: End For assumed at line ... (as I think Martyn was onto in his message). So Turbo probably was detecting the absence of an END FOR and trying to add an explicit one. And probably kept trying to add or find one until it ran into a DEF PROC line and giving up.
At least this is now documented here in case one of us runs into it again.
(If this message is garbled at the edges, it's because it's typed on an Android - not Andrew'ed! - phone and the typing box still goes off the right edge of the screen so typing is blind there)


Derek_Stewart
Font of All Knowledge
Posts: 4779
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Christmas Fun

Post by Derek_Stewart »

The cotrect usage is clearly defined on the Superbasic / Sbasic Reference Manual.

So no real excuse for not knowing about the correct syntax.


Regards, Derek
User avatar
bwinkel67
QL Wafer Drive
Posts: 1545
Joined: Thu Oct 03, 2019 2:09 am

Re: Christmas Fun

Post by bwinkel67 »

So I modified it a bit so that it loops...it prints all the screens first (also included turbo toolkit with boot program). Plus, I fixed it to work with JS SuperBasic. It's called Claus_bas:

Santa2.zip
(43.02 KiB) Downloaded 91 times

...and a 128K version on MDV (had to remove the last screen) called Claus_128K_bas:

MDV.zip
(43.33 KiB) Downloaded 108 times
Last edited by bwinkel67 on Fri Dec 30, 2022 10:11 pm, edited 2 times in total.


User avatar
bwinkel67
QL Wafer Drive
Posts: 1545
Joined: Thu Oct 03, 2019 2:09 am

Re: Christmas Fun

Post by bwinkel67 »

Here is an animated GIF of the repeating part. Merry Christmas!

Claus-small.gif
Claus-small.gif (492.5 KiB) Viewed 1578 times


... and a larger one (click to see it animate)

Claus.gif


User avatar
Cristian
QL Wafer Drive
Posts: 1024
Joined: Mon Feb 16, 2015 1:40 pm
Location: Veneto

Re: Christmas Fun

Post by Cristian »

So nice!


User avatar
XorA
Site Admin
Posts: 1655
Joined: Thu Jun 02, 2011 11:31 am
Location: Shotts, North Lanarkshire, Scotland, UK

Re: Christmas Fun

Post by XorA »

QL art that is not green and red \o/

Looks awesome!


User avatar
Andrew
QL Wafer Drive
Posts: 1047
Joined: Tue Jul 17, 2018 9:10 pm

Re: Christmas Fun

Post by Andrew »

The 4 screens:
Img1.jpg
Img2.jpg
Img3.jpg
Img4.jpg


User avatar
vanpeebles
Commissario Pebbli
Posts: 2853
Joined: Sat Nov 20, 2010 7:13 pm
Location: North East UK

Re: Christmas Fun

Post by vanpeebles »

Wow that looks great :D


Post Reply