Difficulty: Beginner to Intermediate | Prerequisites: Data Types, Variables, and Functions (CS 101 Study Notes, Part 1)
These three topics build on the foundations of data types, variables, and functions. Control flow governs how a program decides what to do and when to repeat itself. Object-oriented programming introduces a way of organising code around "objects" that bundle data and behaviour together. Debugging is the practical skill of finding and fixing the mistakes you will inevitably make. If you are comfortable with variables and functions, you are ready for this material.
Control flow lets your program make decisions (if/else), repeat actions (loops), and branch between options (switch). Object-oriented programming organises code into classes and objects so related data and logic live together. Debugging is the process of tracking down and fixing errors, and it is a skill you will use every single time you write code.
Control flow
The order in which individual statements, instructions, or function calls are executed in a program.
Think of it as: the path the computer follows through your code. Without control flow tools, it just runs every line top to bottom, once.
If/else statement
A conditional structure that executes one block of code if a condition is true and a different block if it is false.
In simple terms, this means: the program asks a yes/no question and does different things depending on the answer.
Loop
A structure that repeats a block of code multiple times, typically until a condition is no longer met.
Think of it as: telling the computer "keep doing this until I say stop."
For loop
A loop that runs a set number of times, controlled by an initialiser, a condition, and an increment.
In simple terms, this means: "start here, keep going while this is true, and step forward by this much each time."
Switch statement
A control structure that tests a single variable against multiple possible values (cases) and executes the matching block.
Think of it as: a menu. The program checks which option matches and jumps to that case.
Class
A blueprint or template that defines the properties (data) and methods (functions) an object of that type will have.
In simple terms, this means: a class describes what something is and what it can do; an object is an actual instance of that description.
Object
An instance of a class, created at runtime, holding its own copy of the class's properties.
Think of it as: if the class is the architectural plan, the object is the house built from it.
Method
A function that belongs to a class and operates on the object's data.
In simple terms, this means: an action an object knows how to perform.
Syntax error
An error caused by code that does not follow the language's grammar rules. The program will not compile or run.
Think of it as: a spelling or punctuation mistake in code. The compiler does not understand what you wrote.
Logical error
An error where the code runs without crashing but produces the wrong result because the logic is flawed.
Think of it as: following a recipe correctly but the recipe itself is wrong. The cake comes out, but it tastes terrible.
Runtime error
An error that occurs while the program is running, often caused by unexpected conditions like dividing by zero.
In simple terms, this means: the code compiles fine, starts running, then hits a problem it cannot handle and crashes.
The program evaluates a condition (a boolean expression). If it is true, the first block runs. If false, the else block runs.
Example:
if (age >= 18) {
cout << "You are an adult.";
}
else {
cout << "You are not an adult yet.";
}
The condition inside the parentheses must evaluate to true or false. This is where boolean logic from the data types unit becomes practical.
A for loop bundles three things into one line: where to start, when to stop, and how to step.
Example that prints the numbers 0 through 9:
for (int i = 0; i < 10; i++) {
cout << i;
}
int i = 0 is the initialiser (start at 0).
i < 10 is the condition (keep going while i is less than 10).
i++ is the increment (add 1 to i each time).
Useful when a single variable needs to be tested against many possible values.
Example:
switch (dayOfWeek) {
case 1:
cout << "Monday";
break;
case 2:
cout << "Tuesday";
break;
// and so on...
}
Each case is followed by a break; to prevent fall-through (running the next case's code unintentionally).
OOP uses classes as blueprints and objects as instances built from those blueprints.
A class defines properties (what the object knows) and methods (what the object can do).
Example:
class Person {
public:
string name;
int age;
void sayHello() {
cout << "Hello, my name is " << name
<< " and I am " << age << " years old.";
}
};
Creating and using an object:
Person john;
john.name = "John Doe";
john.age = 25;
john.sayHello();
john is an object of type Person. It has its own name and age, and it can call sayHello() on itself.
The public: keyword means the properties and methods are accessible from outside the class. Access control is a topic that builds on this later in the course.
Three categories of error to watch for:
Syntax errors prevent the code from compiling. A missing semicolon or mismatched brace is a syntax error.
Logical errors let the code run but produce incorrect output. These are the hardest to find because nothing "breaks" visibly.
Runtime errors crash the program mid-execution, often from unexpected input or illegal operations (like dividing by zero).
Practical debugging strategies:
Read the error message. Compilers and interpreters tell you the line number and often the nature of the problem.
Use print statements to output variable values at key points, so you can see where the program's state diverges from what you expected.
Step through code line by line using a debugger (built into most IDEs). This lets you watch variable values change in real time.
Control flow is everywhere. A login screen uses an if/else to check your password. A music player loops through a playlist. A vending machine's logic is a switch statement matching your selection to a product. OOP is the dominant paradigm in large-scale software: video games model characters as objects, web frameworks model pages and requests as objects, and mobile apps model UI elements as objects. Debugging is the single skill that separates someone who writes code from someone who ships working code.
Students often forget the break; in a switch statement and wonder why multiple cases execute. Without break, execution falls through into the next case.
A common mistake is confusing = (assignment) with == (comparison) inside an if condition. Writing if (x = 5) assigns 5 to x rather than checking whether x equals 5.
Students sometimes think OOP is just "putting code inside a class." The point is to group related data and behaviour together so the design reflects the problem being solved.
Many students treat debugging as random trial and error. Systematic strategies (read the error, isolate the problem, test a hypothesis) are far more effective and what examiners expect you to describe.
⚠️ Expect to trace through an if/else or a loop and state the output. Practice doing this by hand on paper.
⚠️ Switch statement fall-through (missing break) is a favourite exam trap. Know what happens when you leave it out.
⚠️ Be ready to write or read a simple class definition and identify its properties and methods.
⚠️ Know the difference between syntax, logical, and runtime errors, with an example of each.
True or false: A for loop always runs at least once. ______
Fill in the blank: In a switch statement, the ______ keyword prevents execution from falling through to the next case.
True or false: An object is the same thing as a class. ______
Fill in the blank: An error that crashes the program during execution is called a ______ error.
True or false: if (x = 10) checks whether x is equal to 10. ______
Answers: 1. False (if the condition is false from the start, it runs zero times). 2. break. 3. False (a class is the blueprint; an object is an instance of that blueprint). 4. Runtime. 5. False (it assigns 10 to x; the comparison operator is ==).
Q: What are the three components of a for loop's header?
A: The initialiser (sets the starting value), the condition (checked before each iteration), and the increment (updates the counter after each iteration).
Q: What happens if you omit break; from a case in a switch statement?
A: Execution falls through into the next case's code, running it regardless of whether that case matches, until a break is reached or the switch block ends.
Q: In OOP, what is the relationship between a class and an object?
A: A class is a blueprint that defines properties and methods. An object is a specific instance created from that class, holding its own values for those properties.
Q: Name the three types of errors and give one example of each.
A: Syntax error (missing semicolon), logical error (using + instead of - in a calculation), runtime error (dividing by zero).
Q: Why are print statements useful for debugging?
A: They let you output the value of variables at specific points in the code, so you can see where the program's actual state diverges from what you expected.
Control flow builds directly on booleans and comparison operators from the data types unit; every if condition is a boolean expression. OOP extends the concept of functions and variables by bundling them into classes, which becomes the foundation for inheritance and polymorphism later in the course. Debugging is relevant to every topic going forward, because every piece of code you write can contain errors, and the earlier you build systematic debugging habits the less time you spend stuck.
control flow, if else, conditional statements, for loop, while loop, switch statement, case, break, fall-through, object-oriented programming, OOP, class, object, instance, method, properties, encapsulation, debugging, syntax error, logical error, runtime error, compiler error, IDE, debugger, print debugging, C++ control flow, CS 101, coding fundamentals, UCF Computer Science I, intro to programming, decision structures, iteration, repetition