Category

Conditions and Loops

Conditions with if, else if, and else

The if statement makes it possible for a program to decide whether or not to run a chunk of code. The decision depends upon a condition, which will evaluate to…

Jul 14, 2026 →

The switch Statement

The switch statement selects one path to execute from multiple options, based on matching the value of an expression to a set of constant cases. It's really a s…

Jul 14, 2026 →

while Loops

A while loop executes a code block as long as some condition remains true. The program evaluates the condition before every execution of the block. If the condi…

Jul 14, 2026 →

do-while Loops

A do while loop executes its body first and only then checks its controlling condition. Because the test occurs after the body, the statements within the body a…

Jul 21, 2026 →

for Loops

Learn the initialization, condition, update, and body of a for loop, including scope, multiple expressions, and common off-by-one errors.

Jul 21, 2026 →

break and continue

The keywords break and continue can be used within loops to change their normal flow of execution. Each is typed as a single word with a semicolon immediately a…

Jul 14, 2026 →

Nested Loops

Nested loops are loops within the bodies of other loops. For each iteration of the outer loop, the inner loop runs from the start to the end of its own statemen…

Jul 14, 2026 →

Range-Based for Loops

A range-based for loop iterates over every element of a sequence without an explicit index and no explicit step of iteration. The loop variable is automatically…

Jul 14, 2026 →

Common Loop Errors

A loop tends to fail for one of a few reasons. Usually, these problems stem from a condition that doesn't eventually go to false, from a boundary that is off by…

Jul 14, 2026 →
About CppLearn

CppLearn is an interactive, free reference for modern C++. In each lesson, you'll find out how the language works, rather than just lines of code that you can copy and paste. We cover concepts starting from beginner lessons on fundamentals and proceed to templates, move semantics, smart pointers, and areas that usually trap or scare C++ learners.