top of page
Incrementing Variables
Instead of using variable = variable + 1 to increment a variable we can use the increment operator ++
Example:
Output:


The output adds one number as expected per loop until the loop is no longer valid.
Order of Operations
When performing some tasks it is important to remember order of operations. As we previously incremented with variable++ we can also increment with ++variable This will add one to the function before the function is carried out.
Example:
Output:


The program will make y equal to a before a is incremented to 1 whereas z will be equal to b after it is incremented to 1.
bottom of page