Constants and variables
Learning Intentions & Success Criteria
Learning intentions (He koronga ako):
- What constants and variables are used for
- How to store values in constants and variables
- How to use constants and variables with the print function
Success criteria (He paearu angitū):
- You can explain the difference between a constant and a variable
- Your program:
- Declares at least one constant and at least one variable
- Assigns values to the constant and variable
- Displays the constant and variable values using the
print()function
Constants and variables
Ngā taurangi me ngā kauriterite
What are constants and variables?
- In computer programming, constants and variables are like containers that store information.
- Think of them like boxes with labels on them.
- Inside the box is a piece of data (like a name or a number), and the label is the name you give that container.
Constants vs. Variables
- Constant: A container for a value that cannot change once it’s been set. Think of it like a permanent marker.
- Variable: A container for a value that can change while the program is running. Think of it like a whiteboard.
Declaring a constant
- In Swift, we use the
letkeyword to declare a constant. - Use a constant when you know a value will stay the same throughout your program (e.g., your date of birth).
```swift let name = “Rāwiri”