Input, decisions and loops
Reading input, making decisions with conditions and repeating work with loops.
About 4 hours of study
Learning objectives
- Read data from the standard input
- Choose code with conditions
- Repeat code with loops
Lessons
- 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
Operators and conditions
Arithmetic and comparison operators, if, elseif and else, the ternary and null coalescing operators, switch and match.
- 3
Loops
Repeating code with for, while, do-while and foreach, and controlling loops with break and continue.
Module practice
- PHP: Sum of two numbersEasy
- PHP: Sum and averageMedium
- PHP: Read until the endHard
- PHP: Even or oddEasy
- PHP: Leap yearsMedium
- PHP: Kind of triangleHard
- PHP: A times tableEasy
- PHP: Digits of a numberMedium
- PHP: A number pyramidHard