07.05.2015 Views

Bronze Edition Guide - True BASIC

Bronze Edition Guide - True BASIC

Bronze Edition Guide - True BASIC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

10. Formatting and Printing Your Program 67<br />

Now select the Do Format command in the Run menu. This command indents the statements<br />

inside structures and puts all keywords into uppercase. You should find the structures<br />

much easier to follow. (In fact, Do Format is a good first step in debugging your program.<br />

Chapter 18 has more information on that.)<br />

! Program to play a guessing game.<br />

!<br />

RANDOMIZE<br />

LET answer = Int(Rnd*6) + 1 ! Choose number from 1 to 6<br />

PRINT “I’m thinking of a number from 1 to 6.”<br />

PRINT “You have 3 chances to guess it.”<br />

PRINT<br />

FOR chance = 1 to 3<br />

PRINT “Enter your guess”; ! Ask for number<br />

INPUT guess<br />

IF guess = answer THEN<br />

PRINT “Correct!!!”<br />

STOP<br />

! Stop here, you guessed it<br />

ELSE<br />

! Analyze wrong answers<br />

IF guess > answer then<br />

PRINT “Too high. Guess again.”<br />

ELSE<br />

PRINT “Too low. Guess again.”<br />

END IF<br />

END IF<br />

NEXT chance<br />

PRINT<br />

PRINT “The number was”; answer<br />

END<br />

You should now be able to easily see and follow the nested IF structure that is in the<br />

ELSE segment of the first IF structure.<br />

To make this program even more readable, you could add some blank lines. Remember<br />

how to do this? Place the cursor (horizontal blinking bar) at the end or beginning of a line<br />

and press the RETURN-key. Use the DELETE-key at the beginning of the line to remove<br />

undesired blank lines.<br />

Indenting Blocks with > and < keys<br />

You can, of course, indent single lines by adding spaces at the beginning of the line.<br />

You can also easily indent a block of lines in <strong>True</strong> <strong>BASIC</strong>. First, select the lines you wish<br />

to indent by dragging across those lines with the mouse cursor. (Make sure than the entire

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

Saved successfully!

Ooh no, something went wrong!