Separate speaker notes to accompany PowerPoint presentation of BBC Basic:
This is available for download at:
This is a more traditional version of basic. Here I am declaring a variable of num1 with a value of 5 and a variable num2 with a value of 7. Then I am adding them up and putting the result in ans. Finally, I am printing ans to the screen.
Note that the Basic Command PRINT is in upper case.
This takes in payhr and hrswk using the INPUT command. The command is in upper case, then the prompt is shown and then the place to store the users response (either payhr or hrswk). Next I calcualte grosspay and then print out the message followed by the results of the calculation. The comma between the two fields in the output results in the space between My pay is and 400.
I changed the comma to a semi-colon between the literal My pay is and grosspay. This eliminated the large number of spaces between them. Essentially the comma makes columns and the semi-colon puts the things together.
This shows an IF statement. After calculating the grosspay, I ask if it is less then 1000. If it is, I print the literal I need a raise!
Note the syntax of the IF including the ENDIF.
Since the gross pay was 800 and 9=800 is less then 1000, the PRINT was executed.
In this example the grosspay was not less then 1000 so the PRINT was not executed.
In this example, I am testing grosspay to see if it is less then 1000 and either way, I am printing a literal.
In this case the grosspay is not less then 1000 so the else is executed and the literal Gross pay is okay!
This shows the literal that is printed when the grosspay is less then 1000.
This is a FOR loop. I am starting the variable i at 1 and I am going to stop when the variable i = 5. The command is:
FOR i = 1 TO 5
Inside the loop, I added i to i and then printed the i followed by a semi-colon and then the literal + with a space before and after it. Then I put in the semi-colon to separate followed by another i and a semi-colon. Then I put in the = with quotes on either side followed by a semi-colon. Finally I put in the ans that I calculated. You can see the results.
In this example, I am using a loop. I input the number of times I want to do the loop and store that in the variable num. Then I input the amount I want to deposit to the account each time.
Next, I set a ct equal to 1 to count the number of times I do the loop.
Next comes the loop. It uses REPEAT as the command and the bottom line in the loop is the UNTIL that tells how many times to do the loop.
Inside the loop, I print out amt and the current value of ct along with two literals. Notice that each thing I print is separated with a semi-colon. Then I add the amount to totamt and add 1 to ct. Note that since I did not initialize totamt it starts at 0.
When the loop is complete, I print out the literal saying the total is followed by totamt.