Unit 3
3.1 Variables & Assignment
A variable stores a value
Use assignment to give it a value
Example:
x ← 5
name ← "James"Key Idea:
Variables can change during a program
3.2 Data Types
Integer → whole numbers
Decimal (Float) → numbers with decimals
String → text
Boolean → true/false
3.3 Mathematical & Logical Operations
Math:
+, −, ×, ÷, MOD (remainder)
Logic:
AND → both must be true
OR → one must be true
NOT → reverses truth
3.4 Expressions
A combination of values and operations
Example:
x + 5
score > 103.5 Input & Output
Input → data given to program
Output → result shown
Example:
DISPLAY("Hello")
INPUT(age)3.6 Conditionals (Selection)
Code that makes decisions
Example:
IF score > 90
DISPLAY("A")
ELSE
DISPLAY("Not A")3.7 Nested Conditionals
Conditionals inside conditionals
3.8 Iteration (Loops)
For Loop
Repeats a fixed number of times
FOR i ← 1 TO 5
DISPLAY(i)While Loop
Repeats while condition is true
WHILE x < 10
x ← x + 13.9 Algorithms
A step-by-step solution to a problem
Must be:
Clear
Finite
Effective
3.10 Lists (VERY IMPORTANT)
Store multiple values
Example:
numbers ← [1, 2, 3]Operations:
Access → numbers[1]
Add → APPEND
Remove → REMOVE
3.11 Traversing Lists
Going through each element
Example:
FOR each item IN list
DISPLAY(item)3.12 Procedures (Functions)
Reusable blocks of code
Example:
PROCEDURE greet(name)
DISPLAY("Hello " + name)3.13 Parameters & Return Values
Parameter → input to procedure
Return → output from procedure
3.14 Abstraction
Hiding complex details
Makes code easier to use and reuse
3.15 Developing Algorithms
Combine:
Sequencing (order)
Selection (if)
Iteration (loops)
3.16 Testing & Debugging
Syntax error → code won’t run
Logic error → wrong output
Runtime error → crashes while running
BIG IDEAS (SUPER IMPORTANT)
Programs use:Variables
Conditionals
Loops
Lists
Algorithms must be:
Step-by-step
Logical
Lists + loops = powerful combo
Abstraction simplifies complexity
COMMON AP EXAM QUESTIONS
Be ready to:
Trace code (predict output)
Identify errors
Understand loops + lists
Compare algorithms (efficiency, correctness)
Explain what a procedure does