← All lectures

Lecture 07 · 35 min

if, else if & Decision Statements

Simple if, if-else, blocks, multi-way else-if ladders, and the bool data type in conditions.

Simple ifBlocks {}if-elseMulti-way ifRelational & logical ops
Slide 1 / 17

Why do we need decisions?

Real programs don't do the same thing every time. They need to react to different situations:

  • If the user enters a negative number, show an error
  • If the score is above 90, print "A"
  • If the username and password match, allow login

Decision statements let your program take different paths depending on conditions.

← / → navigateF fullscreenEsc exit⌘K search