-->

Coding with FUZE BASIC – Part 1

Variables are used in programming to store and retrieve data from the computer’s memory. It’s a specified location in memory that can be referenced by the programmer at any point in the code, as long as it’s created and valid.

LET THERE BE VARIABLES


We’ve already looked at assigning some variables in the previous tutorial so let’s extend that and see what else we can do with them.

You May Also Like:


Step 1

Enter the Program Editor, by pressing the F2 key. Within the Program Editor enter the following, pressing Enter after each line:

Let x=10Print x

Now click on the Save button, along the top of the screen and save the program as ‘Variables1’. Click the OK button to return to the Editor and the Run button to execute the code.

Coding with FUZE BASIC – Part 1
Coding with FUZE BASIC – Part 1


Step 2

After clicking Run you drop back into Immediate Mode and the display will output the number 10. To break down this simple code, you’ve created the variable called X, and you’ve allocated the value 10 to it. The second line simply prints the current value of X – which is of course, 10.



Step 3

Press F2 to enter Editor mode and click on New. Now let’s expand on the simple code. Enter the following:

Let x=10Let y=20Let z=30Print x + y + z

Save as ‘Variables2’ and Run it. You now have the output of 60 on the screen, as you’ve assigned X, Y and Z with numerical values, and printed the total.



Step 4

What if we wanted to change the value of a variable? Enter this listing:

Let x=10Let x=x-1Print x

To begin with X equalled 10 but the next line subtracts 1 making it 9, then prints the current value of X. Imagine this as lives in a game, starting with 10 lives, losing 1 and leaving 9 left.



Step 5

We can extend this further with more commands. Try this:

Let x=10CyclePrint xLet x=x-1Repeat until x=0Print “Blast Off!”End

This creates a loop that will minus 1 from X until it reaches 0, then prints Blast Off!



Step 6

Variables can do more than store numbers:

Input “Hello, what is your first name?“, f$PrintInput “Thanks, and what is your surname? “, s$ClsPrint “Hello “; f$; “ “; s$; “. How are youtoday?”End

The variables f$ and s$ store input from the user, then printed it back to them on the same line.



Step 7

Conditional statements allow you to make your program do different things depending on the user
input. For example:

clsInput “Enter your name: “, name$If name$=”Dave” thenPrint “I am sorry “; name$Print “I am afraid I can’t do that”ElsePrint “That is not a problem “; name$EndifEndSave as ‘HAL’ and Run.



Step 8

The code from Step 7 introduced some new commands. First we clear the screen, then ask for user input and store it in the variable name $. Line 3 starts the conditional statement, if the user enters the name ‘Dave’ then the program will print HAL’s 2001 infamous lines. If another name is inputted, then it will print something else.



Step 9

Programs store all manner of information, retrieving it from memory in different ways:

clsData “Monday”, “Tuesday”, “Wednesday”Data “Thursday”, “Friday”, “Saturday”Data “Sunday”Dim DaysOfWeek$(7)For DayNo = 1 TO 7 loopRead DaysOfWeek$(DayNo)RepeatFor DayNo = 1 TO 7 loopPrint “Day of the week number “; DayNo;Print “ is “; DaysOfWeek$(DayNo)RepeatEnd



Step 10

The code from Step 9 is beginning to look quite complex, using the Data command to store constant data, creating a variable called DaysOfWeek using the Dim command and assigning it an indexed dimension (7). The code then Reads the stored Data, assigns it a variable dimension from 1 to 7 and prints the result.



0 Response to "Coding with FUZE BASIC – Part 1"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel