4️⃣

3.4 Augmented Assignment Operators

Augmented Assignment Operators

These are shortcuts for updating a variable using arithmetic.

The below table's right and left columns are equivalent

Table

a += b

a -= b

a *= b

a /= b

a %= b

is equivalent to

is equivalent to

is equivalent to

is equivalent to

is equivalent to

a = a + b

a = a - b

a = a * b

a = a / b

a = a % b

Practice

Number

Initialize a variable number with a value of 5.

Then, using augmented assignment operators:

  1. Increase it by 4
  2. Decrease it by 3
  3. Multiply it by 2
  4. Divide it by 3

Finally, print the result.

Previous Section

Next Section

⚖️

Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.