FAQ  •  Register  •  Login

Compounded Let statments

<<

emook

Posts: 27

Joined: Tue Dec 06, 2016 1:23 am

Post Thu Feb 02, 2017 1:17 pm

Compounded Let statments

Hello,

I've noticed that somthing that is possible is Sinclair Basic doesn't seem possible in Boriel....

eg:

Sinclair Basic

10 LET x=0
20 LET x=x+1-(50 AND x=50)
30 PRINT AT 0,0;x,
40 GOTO 20

As you can see x=x+1 will increment minus 0 unless x=50 then it will subtract 50. Great for loops and counters. In ZXB I am having to expand this into IF THEN statements.

x=0
x=x+1
myloop:
IF x=50 THEN
x=0
END IF
Print at 0,0;x,
GOTO myloop
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Fri Feb 03, 2017 11:03 pm

Re: Compounded Let statments

True :shock:
I didn't know this behaviour.
Where can I find more info about this?

anyway, the fastest way to this is:
  Code:
DIM x AS Byte = 0
myloop:
x=(x+1) MOD 50
PRINT AT 0,0;x,
GOTO myloop
<<

emook

Posts: 27

Joined: Tue Dec 06, 2016 1:23 am

Post Sun Feb 05, 2017 1:47 am

Re: Compounded Let statments

It is mentioned very briefly in the ZX Basic manual, http://www.worldofspectrum.org/ZXBasicM ... hap13.html

But turns out to be far more useful. See this program that creates the +2 test screen :

10 FOR l=0 TO 21 : FOR i=7 to 0 STEP -1 : PRINT INK (l and l<8); PAPER i;("19" AND l<8); (" " AND l>= 8 ) ; BRIGHT 1; ("86" AND l<8); (" " AND l>=8);: NEXT i : NEXT l

You can see a live version of it here :
Run demo
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sun Feb 05, 2017 9:07 pm

Re: Compounded Let statments

Ok. I see.
I'll try to implement that, but with only in "--sinclair" mode. Otherwise bool comparisons will be slower :roll:

Perhaps it would be better to implement the ? : operator like in C??
What do you people think?
<<

Haplo

User avatar

Posts: 9

Joined: Tue May 12, 2015 5:09 pm

Post Tue Feb 07, 2017 10:03 am

Re: Compounded Let statments

boriel wrote:Perhaps it would be better to implement the ? : operator like in C??


I think that is a good idea, it could help to do more readable the code.

Return to ZX Basic Compiler

Who is online

Users browsing this forum: No registered users and 2 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO