Presentation is loading. Please wait.

Presentation is loading. Please wait.

CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.

Similar presentations


Presentation on theme: "CRE Programming Club - Class 2 Robert Eckstein and Robert Heard."— Presentation transcript:

1 CRE Programming Club - Class 2 Robert Eckstein and Robert Heard

2 What Are Variables Again? Variables vary (change), and constants are constantly the same. In the world of programming, there are values in your program that need to change all the time, and there are values that will stay the same. For the most part in Small Basic, you’ll be using variables.

3 Variables How do we create a variable in Small Basic? Well, we just give it a name and set it equal to something. Most variables names are short words or single letters. A = 20 This is kind of like getting a box, writing “A” on the outside, and putting the number 20 inside of it. If you come along later and say, “Hey, I’d like to use what’s in A, you’re going to get 20.” At this point in the program, A = 20.

4 Variables Let’s test that out by adding the following line afterwards: TextWindow.WriteLine(“A is “ + A) This command will write out the current value of A. What happens if we put the following after it? A = 21 TextWindow.WriteLine(“A is “ + A)

5

6

7 What Can a Variable Store? So what can a variable store? Well, with Small Basic, one of two things. We already know it can store a number. For those of you working with fractions and decimals, variables can store any number, including those with decimals. So, 40 and a half would be written as 40.5.

8 Variables Can Also Store Words! Hmmm… how do computers handle words? Well, kind of like what you did as a baby with building blocks. Remember that computers are dumb and they really, really love codes. Turns out the computer has a code number for each letter, a code number for a space, a code number for a questions mark, and, well… a code number for pretty much everything on your keyboard.

9 What Can a Variable Store? When it wants to use words, it just strings the letters and symbols together like the building blocks of a baby. And, when it’s done, it adds on a special code (usually 0) that says, “Okay, this is the end of the it!” So, we know about numbers, but what are these words or sets of words or symbols or whatever called?

10 Strings Must Have Quotes! Let’s write a string and assign it to a variable. A = “Hello There!” Note that a string is always surrounded by double quotes. What happens if we write? A = Hello Small Basic will think we want to take the value in the variable Hello and copy it into A.

11 Try Some of These... A = “Hello There” A = 12 + 45 A = 1 + 9 * 4 A = B A = A + 1 A = (B * C) / D A = Math.PI A = Math.PI * R * R A = currentArea - 1 A = “Hello “ + “There” A = “12” + “34” A = “Hello “ + 12 Set the other variables (B, C, D, currentArea) to something if you need to! Can you set Math.PI to something?

12 Adding Strings and Numbers What happens if we add two numbers together? What happens if we add a number to a String? Experiment and see what happens! A = “Hello” A = A + “ There ” A = A + 12

13 Point of Execution This tells the exact point where the program is executing. A program will execute line by line. When it finishes one line (a statement), it moves onto the next. And the next. And the next. And it keeps going, unless you tell it to go somewhere else in the program. So if I tell it later that A = 21, then 20 gets thrown away, and A now equals 21.

14 No Confusion So, the important thing to remember here is: a program won’t do what it’s told to do UNTIL IT GETS to that line, and when it gets done executing that line, THE COMPUTER HAS DONE IT.

15 Computers are Dumb Like they said in the video last week, deep down computers are pretty dumb. But they’re actually a little like football quarterbacks. Have you ever seen a football quarterback come up to the line and say something like “43! 21!”. Each of those numbers is a secret code that means something to the other players.

16 Computers are Dumb Computers are the same way. They get a number like 43, and that tells them do so something. And then they get a number like 21, and that’s a code too. And they know what to do with that number too! Each code number means something, and it never changes. This is called machine language.

17 Next Time.... Keep experimenting with variables between this class and the next! Try things at home! Next time, we’re going to learn some more about how computers work and some of the branching functionality that is available.


Download ppt "CRE Programming Club - Class 2 Robert Eckstein and Robert Heard."

Similar presentations


Ads by Google