Programming foundations

Stage 1 · Lesson 3 of 9

Conditionals and loops

Your first language

(if, elif and else) let a program choose between paths, and let it repeat work. Use a for loop to walk over anything you can step through, such as the letters of a word (for ch in word) or a range of numbers. for i in range(5) gives 0 to 4, not 1 to 5.

Use a while loop when you do not know the count in advance, such as asking again until the input is valid. Make sure something inside it changes the condition, or it never ends. break leaves a loop early and continue skips to the next pass.

Python also treats empty strings, 0, and empty lists as false. These are called . They keep conditions short, but they hide bugs when 0 is a valid value. Trace small loops on paper until the counts feel obvious.

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

Resources for this stage

Start with· follow one of these

Practise

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

Keep handy

  • The official tour: read the matching chapter after the course covers a topic

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

Mark this stage as not done?