19.04.2017 Views

Learn to Program with Small Basic

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Figure 4-2: How a variable is added <strong>to</strong> the IntelliSense menu<br />

Note how the name of the variable created in the first statement<br />

(interestRate) appears in the menu. When I started <strong>to</strong> type in on the second<br />

line, the IDE highlighted the name of the variable. Pressing the enter key<br />

au<strong>to</strong>completes what I started <strong>to</strong> type. Thanks, IntelliSense!<br />

Avoid Naming Variables After Methods and Objects<br />

Method names aren’t reserved keywords, so you could use them as variable<br />

names. For example, <strong>Small</strong> <strong>Basic</strong> won’t complain if you write this:<br />

writeline = 5<br />

TextWindow.WriteLine(writeline)<br />

Although this is valid, we strongly recommend you don’t name your<br />

variables after existing methods. The world is confusing enough already.<br />

TRY IT OUT 4-2<br />

1. Which of these variable names are invalid? If the name is invalid, explain why.<br />

_myBooK<br />

1MoreRound<br />

$FinalScore<br />

Level2<br />

2. For each of the following values, what would you name a variable that represents<br />

it, and why?<br />

• The score of a player in a game<br />

• The hypotenuse of a right triangle<br />

• The number of floors in a building<br />

• The number of miles a car can drive per gallon of fuel<br />

• The number of licks it takes <strong>to</strong> get <strong>to</strong> the center of a Tootsie Pop<br />

Using Variables 49

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!