> Sford wiki > Sford Basic tutorial > Sford Basic tutorial 3

1 - 2 - 3 - 4

You now know these commands:

Time now to learn about variables.

Computers have memory. You may have heard people talk about how many megabytes or gigabytes of RAM or memory their computer has. What is memory used for? Well, for one thing, it is used to hold your program. But it also holds data. By data I mean information that would not always be the same. For example, type this:

10 legal_age = 21
20 print "You must be "; legal_age; " to drink"

In line 10, you created a variable to hold a number. You named that variable "legal_age". Notice that it uses an underscore (_) instead of a space. This is because a variable name is not allowed to contain spaces. It can only be letters, numbers, and underscore. This variable holds a number.

You can also have variables that hold strings. For example:

3 name$ = "Celia"
20 print name$; " must be "; legal_age; " to drink"

The dollar sign at the end of the variable name tells Basic that the variable should hold a string, not a number.

Time for a new command: "input".

3 print "What is is your name?"
4 input name$

This lets the program get information from the person running the program. Let's make the program more interesting:

7 print "How old are you?"
8 input age
30 print name$; " must wait "; legal_age - age; " years"

One more command for this lesson:

40 goto 3

Ever hear of an "infinite loop"? That's what you've got. To get out of the program, you have to pull down the "Control" menu and select "Stop".

You've written a useful program!

Let's save this one with the name "age1" (File->Save as, use "Celia" folder)

Ready for Sford Basic tutorial 4?

Retrieved from "http://wiki.geeky-boy.com/w/index.php?title=Sford_Basic_tutorial_3"