Input, decisions and loops

Reading input, making decisions with conditions and repeating work with loops.

About 4 hours of study

Learning objectives

Lessons

  1. 1

    Input from STDIN

    Reading lines, numbers and lists from the standard input with fgets, fscanf and explode, and reading until the input ends.

  2. 2

    Operators and conditions

    Arithmetic and comparison operators, if, elseif and else, the ternary and null coalescing operators, switch and match.

  3. 3

    Loops

    Repeating code with for, while, do-while and foreach, and controlling loops with break and continue.

Module practice

Module quiz

1. Which function reads one line from the standard input?
2. Which loop always runs its body at least once?
3. What does 17 % 5 give?
4. Which comparison also checks the type?
5. What does break do inside a loop?
6. What does fgets(STDIN) return when the input has ended?

‹ PHP basicsArrays and functions ›