9618 · 11.1
Programming Basics
Learn how to create the fundamental elements of any program: variables and constants. We'll see how to give data a name and a type, and how to store and change values as your program runs.
Need to know
What you need to know
- **Variable**: A named memory location whose value can change while the program is running. Use a variable for things like a user's score, their current input, or a counter in a loop.
- **Constant**: A named memory location whose value is set once and cannot be changed. Use a constant for values that must remain fixed, such as the rate of VAT, the value of Pi, or a game's maximum number of lives.
- **Identifier Rules**: Good practice, and often a requirement, is to use meaningful names (e.g., `PlayerScore` instead of `x`). Identifiers cannot contain spaces and usually cannot start with a number.
Explanation
Programming's Building Blocks
- First, identify the pieces of information your program needs to store, like a player's score or a fixed tax rate.
- For each piece of data, choose the most appropriate data type, such as INTEGER for a whole number or STRING for text.
- Declare a named container (a variable or constant) in your code, specifying its name and data type.
- Use the assignment operator to place an initial value into your declared variable or constant.