© Gerald Friedland 2019
Gerald FriedlandBeginning Programming Using Retro Computinghttps://doi.org/10.1007/978-1-4842-4146-2_9

9. Math and Variables

Gerald Friedland1 
(1)
Berkeley, CA, USA
 

Can you do math with variables ? Yes, you can!

Try this:

AGE=6 (press RETURN)

PRINT AGE+1 (press RETURN)

../images/470770_1_En_9_Chapter/470770_1_En_9_Figa_HTML.jpg

What happened?

The result is 7 because AGE is 6 and 6+1=7.

What happens when you try this:

PRINT AGE+2 (press RETURN)

PRINT AGE+3 (press RETURN)

AGE stays 6, and 6+2=8 and 6+3=9. No surprise here.

You can check that AGE is still 6 by typing this:

PRINT AGE

Press RETURN.

Here is the result:

AGE never changed.

Now try this:

AGE=AGE+1 (press RETURN)

PRINT AGE (press RETURN ...

Get Beginning Programming Using Retro Computing: Learn BASIC with a Commodore Emulator now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.