Loops
Repeat work with while, do-while and for, then practise.
5.1The do-while Loop in C: Run First, Check AfterHow C's do-while loop works: the body always runs at least once before the condition is tested. Two PIN-entry examples, plus do-while vs while and common pitfalls.5.2Why Use break in a while Loop If the Condition Already Stops It?If a loop runs while i < 10 but breaks at 4, why write i < 10 at all? The condition is the planned exit and break is the exit for a special case. Four short examples: search, sentinel input, retries and menus.5.3Printing a Comma-Separated List in C (No Trailing Comma, Clean Line Breaks)How to print 0, 1, 2, ... with commas in C: why a plain printf glues the numbers together, four ways to avoid the trailing comma, and how \n works in nested loops for rows of numbers.5.45 while Loop Practice Problems in C (with Hints and Solutions)Five while-loop exercises in C, from printing even numbers to reversing a number: each with a task, expected output, a step-by-step hint, a tested solution, and a harder follow-up.5.55 for Loop Practice Problems in C (with Hints and Solutions)Five for-loop exercises in C, from a multiplication table to a star triangle: each with a task, expected output, a step-by-step hint, a tested solution, and a harder follow-up.5.65 Nested for Loop Practice Problems in C (with Hints and Solutions)Five nested for-loop exercises in C: a rectangle, a multiplication grid, a number triangle, a centred pyramid and a checkerboard. Each has expected output, a hint and a tested solution you can reveal.
Back to top