RisingCoder Full course β†’
Week 1Week 2Week 3Week 4Week 5Week 6Week 7Week 8🐍 Python notes
πŸ”
STUDENT NOTES Β· C & C++ WEEK 2 OF 8

Loops & Functions, C Style πŸ”

The logic you know from Python β€” wearing C's armor: brackets, braces and types everywhere.

1The C for loop β€” three instructions in one line

βš™οΈ
Chip: for (start; keep-going-while; step) β€” where the counter begins, when to stop, how to move. All the loop's rules up front.

2Loops doing real work

3while β€” repeat until the test fails

🐞
Bugly: Forget count-- and the countdown never ends. Some traps are universal. Hehehe.

4Functions β€” with type name tags

πŸ¦‰
Professor Hoot: int add(...) promises: this function returns an int. C checks that promise at compile time β€” no surprises later.

5Recursion β€” the function that calls itself

βš™οΈ
Chip: fact(4) = 4 Γ— fact(3) = 4 Γ— 3 Γ— 2 Γ— 1 = 24. It dives down to the base case (n <= 1), then multiplies its way back up.

6Quick quiz! 🧠

for (int i = 0; i < 3; i++) β€” how many times does the body run?
πŸ’‘ i takes 0, 1, 2 β€” three rounds. Stops when i < 3 fails.
void as a return type means…
πŸ’‘ void = "expect nothing back". Like Python functions without return… but declared honestly up front.

7Your mission πŸš€

Mission 1: Print the table of any number using a for loop.
Mission 2: Write int square(int x) and print square(9).
Mission 3: Write a countdown from 10 that ends with "LIFTOFF!" β€” using while.

Week 2 complete β€” loop commander! πŸ”

Next: arrays and strings β€” and C's famous missing seatbelts.

Go to Week 3: Arrays & Strings β†’

βš”οΈ Or test yourself in the C & C++ Arcade β†’