Programming constructs
- Variable
- A pointer that stores a memory address, which in turn stores data
Example
var = "string"
- Initializing a variable is giving it a value
- Constants
- A variable that doesn't change
- A pointer that stores a memory address, which in turn stores data
- Sequence of instructions
- An order in which instructions are executed
Example:
print("1") print("2") print("3")
- An order in which instructions are executed
- Selection
- Instructions that occur only if a condition is met
Example:
if var == "yes": [...] else: [...]
- Instructions that occur only if a condition is met
- Iteration
- A loop, or repetition
- Count controlled iteration:
- Occurs for a certain number of times
Example:
for i in range(5): print(i)
- Occurs for a certain number of times
- Condition controlled iteration:
- Occurs if a condition is met
Example:
value = yes while value == "yes": value = input("Enter yes or no: ")
- Occurs if a condition is met
- Count controlled iteration:
- A loop, or repetition
- Arrays
- Data structures that can hold multiple values
Example:
fruits = ["Apple", "Banana", "Strawberry"]
- Data structures that can hold multiple values