Programming foundations

Stage 1 · Lesson 3 of 8

Conditionals and loops

Your first language

(if, else if and else) choose between paths. switch picks between whole-number or enum values, and if you forget a break, one case falls through into the next. The classic , for (int i = 0; i < n; ++i), gives you a position number.

The , for (const auto& x : v), walks every element of a container without copying it. A while loop repeats until a condition changes. C++ treats 0 as false and any other number as true.

So if (x = 5) compiles, stores 5 in x and is always true, and -Wall warns you about it. Comparing an int with v.size(), which is (never negative), is another warning worth understanding. Trace loops on paper, because an error here reads memory you do not own.

A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with

  • CourseFree
    LearnCpp.com

    LearnCpp.com · Beginner

    Free, current and careful: chapters 0 to 16 take you from setup to references and std::vector

Practise

  • Small exercises in your language track, with free feedback from a human mentor

Keep handy

  • The standard library reference: check std::vector and std::string pages as you use them

  • Quick syntax lookups and an online compiler for testing a snippet on a shared computer

Mark this stage as not done?