|
Perhaps the most fundamental concept in programming is the concept of variables and constants. You probably know that you'll need to deal with them a lot, so here's a refresher. (To learn about how to implement these concepts in Pascal, go to the course "Implementation In Pascal".) What are Variables and Constants? To answer that question, you'll first need to define a variable. Well, have you ever learnt Algebra before? It's the same concept. Just take a name, and assign it a value. It's that simple. For instance, you could assign a a value of 2. So, a plus a is the same as 2 plus 2, which equals 4. Easy does it. Well, then you may ask, "If it's so simple, why call them variables, and not something else?" Ahh, good question! You see, the name comes from the very nature of variables in programming. They can vary. Sure, I know it wasn't like that in Algebra class, but our aim now is not to find out what x is, but to instead use x as just a storing place for a value. Get the idea? Our x is just a storing place for a value. Then what about constants? Well, constants can be said to be the exact opposite of variables. Instead of just being storage space, a constant replaces values. For example, if we had replaced every occurrence of the word "lamb" with the word "head" in a certain famous nursery rhyme, we would have got: its fleece was white as snow. And everywhere that Mary went, her head was sure to go." Yes, it's a very strange version of the original classic, but that's only if you had read it literally. If I had said that "head" was just a constant representing "lamb", it would have made perfect sense. But what are constants for then? Well, constants were created to make program code more readable by replacing meaningless values with a more meaningful name. A very nifty feature indeed! Some more examples of Variables and Constants Still can't get the idea? Don't worry, here are a few more examples to help you out. (Actually, they're more of analogies than examples...)
Conclusion Now that's we've got variables and constants, you might want to go on to "Control Flow Structures", where another basic concept is revised. Remember though, you don't have to go through these courses in the order they are presented. We have (quite painstakingly) tried to make them independent on their own, so feel free to explore! |
|