PI or not PI, that is the question.

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
Shaun_B
Posts: 393
Joined: Wed Apr 22, 2009 10:22 am

PI or not PI, that is the question.

Post by Shaun_B » Mon Jan 22, 2018 12:56 am

Hi,

I've noticed that on ZX81 BASIC, I can use PI as a variable name (not the token PI), like this:

Code: Select all

     1 LET PI=3.14
     2 PRINT PI
However, I can't use PI in a FOR loop, like:

Code: Select all

     1 FOR PI=0 TO 3
     2 PRINT PI
     3 NEXT PI
Is this a limitation of the FOR command (i.e., can you only use single-character variable names in FOR loops)?

Thanks,

Shaun.

rcade
Posts: 13
Joined: Tue Dec 02, 2014 2:28 pm

Re: PI or not PI, that is the question.

Post by rcade » Mon Jan 22, 2018 1:03 am

Loop variables can only be one character.

User avatar
siggi
Posts: 788
Joined: Thu May 08, 2008 9:30 am
Location: Dauernheim, Germany
Contact:

Re: PI or not PI, that is the question.

Post by siggi » Mon Jan 22, 2018 9:53 am

Variables can also contain SPACES:

Code: Select all

10 LET NOT PI = 0
20 PRINT NOT PI
:mrgreen:
My ZX81 web-server: online since 2007
http://zx81-siggi.endoftheinternet.org/index.html

User avatar
PokeMon
Posts: 2203
Joined: Sat Sep 17, 2011 6:48 pm

Re: PI or not PI, that is the question.

Post by PokeMon » Mon Jan 22, 2018 10:29 pm

There is a distinction between keywords and plain letters.
So PI is not PI (P and I).
Also this is valid :lol:

Code: Select all

10 LET LET=99
20 PRINT LET
30 LET PRINT=88
40 PRINT PRINT

I guess this is handled wrong with the ZX-IDE but this unusual programming style ... ;)

Shaun_B
Posts: 393
Joined: Wed Apr 22, 2009 10:22 am

Re: PI or not PI, that is the question.

Post by Shaun_B » Wed Jan 24, 2018 10:11 pm

You can also do this:

Code: Select all

     1 LET APPLE PI = 3.14
     2 PRINT APPLEPI
Regards,

Shaun.

User avatar
gammaray
Posts: 382
Joined: Sun Apr 17, 2016 2:44 am
Location: Texas

Re: PI or not PI, that is the question.

Post by gammaray » Mon Jan 29, 2018 3:35 am

That is just so wrong!
Finish what you start. Truth is over the mountaintop or six feet under.
4 x TS1000, 2 x TS1500 , 2 x timex 2040 printer, 1/2 x timex 2020 cassette deck, ZXPAND+AY, ZeddyNET, ZXBlast..., unfinished Spectrum...Still no life!

User avatar
siggi
Posts: 788
Joined: Thu May 08, 2008 9:30 am
Location: Dauernheim, Germany
Contact:

Re: PI or not PI, that is the question.

Post by siggi » Mon Jan 29, 2018 9:49 am

Re: PI or not PI, that is the question.
The real question is

Code: Select all

10 if two beer or not two beer ....
:mrgreen:
Siggi
My ZX81 web-server: online since 2007
http://zx81-siggi.endoftheinternet.org/index.html

Post Reply