Working with numbers
Video: Working with numbersSo anytime we're working with variables, we really have two things. We have the variable, the container, the bucket, and we have the different values that we're going to put in it from moment to moment. Now, the most common kind of values in computer programs are numeric values, numbers, and really this is no surprise. Sure, these days, when we use the word computer, we think of a machine. But for hundreds of years, computer was a job. In the 17th, 18th, 19th centuries, you could be employed as a computer.
- Where to go from here
Viewers: in countries Watching now:
Finally, the course compares how code is written in several different languages, the libraries and frameworks that have grown around them, and the reasons to choose each one.
- Writing source code
- Understanding compiled and interpreted languages
- Requesting input
- Working with numbers, characters, strings, and operators
- Writing conditional code
- Making the code modular
- Writing loops
- Finding patterns in strings
- Working with arrays and collections
- Adopting a programming style
- Reading and writing to various locations
- Managing memory usage
- Learning about other languages
Working with numbers
So anytime we're working with variables, we really have two things. We have the variable, the container, the bucket, and we have the different values that we're going to put in it from moment to moment. Now, the most common kind of values in computer programs are numeric values, numbers, and really this is no surprise. Sure, these days, when we use the word computer, we think of a machine. But for hundreds of years, computer was a job. In the 17th, 18th, 19th centuries, you could be employed as a computer.
It just meant a person who computes, someone who does calculations. Then these machines come along and they do it far better than the person ever could. These days we think a computer means hardware. But the reason they were invented was always about number crunching. But we need to be comfortable with our use of numbers. When we're writing programs, we're dealing with bank balances and dollars and cents, the position of a spaceship on the screen, the height and width of a web browser window, the coordinates of a device using geolocation, the amount of milliseconds we've been playing an MP3 song, even colors are represented with numeric ranges of red, green, and blue. All numbers.
So on the next statement, I will set that variable to the number 5. Now, when you're brand-new to programming, lines like a = 5 and b = 10 can look a little weird, particularly if the last time you saw anything like this was equations in school. But remember, when you see the equals sign here, this is not a polite description. This is a command. This is an instruction. This is saying take the value 5 and put it in the variable called a.
I don't care what a was before, but after this line of code is executed, it will have the value 5. This is what the equals sign does. It assigns a value. That's why it's formally called the assignment operator. Now, notice that there are no quotes around the number 5. The number 5 here is referred to as a numeric literal. It represents the fixed value 5. The variable part of this line can change as our program runs, but the literal does not.
Now, as one final note, understand there's a very big difference between creating a variable like this, var b = 123, and creating a variable like this, var c =. Similar looking value, but inside quotes. Well, the first one here, var b, is a number 123. The second one, var c, is a string. Not the number 123, but the digits 1, 2, 3 and sometimes that's a pretty big difference in behavior.
So let's talk about strings next.
Find answers to the most frequently asked questions about Foundations of Programming: Fundamentals .
Here are the FAQs that matched your search "" :
- Q: Using TextEdit with Mac OS 10.9 Mavericks?
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.