Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
Increment Operators.docx58.8 KB Increment Operators - Solution.docx
59 KB
Quick reference
Increment Operators
Increment operators allow us to increase or decrease a number by 1.
When to use
Whenever you want to increase or decrease a number by just 1, use an increment operator.
Instructions
These are the increment operators:
$num++; Output the variable then increment
$num--; Output the variable then decrement
++$num; Increment the variable then output it
--$num; Decrement the variable then output it
Where you put your ++ or -- is important. Put them before the variable to increment/decrement and then output. Put them after to output first, then increment/decrement.
Hints & tips
- Increment operators allow you to increase or decrease a number by 1.
- ++
- --
- putting them before or after the variable matters!
Lesson notes are only available for subscribers.