Menu
Coddy logo textTech

Augmented Assignment Operators

Part of the Fundamentals section of Coddy's GO journey — lesson 19 of 109.

Augmented assignment operators combine an arithmetic operation with assignment. They're shortcuts that make your code cleaner.

Instead of writing:

score := 100
score = score + 50

Use the += operator:

score := 100
score += 50
fmt.Println(score)

Output:

150

Other augmented operators include -=, *=, /=, and %=:

count := 10
count *= 5  // Same as: count = count * 5
fmt.Println(count)

Output:

50
challenge icon

Challenge

Beginner

In this challenge, you'll practice using augmented assignment operators in Go. Augmented assignment operators combine an arithmetic operation with assignment (like +=, -=, *=, /=, %=).

We have a variable score that starts at 10. Your task is to use augmented assignment to increase the score by 5.

Cheat sheet

Augmented assignment operators combine arithmetic operations with assignment, making code cleaner:

Instead of:

score = score + 50

Use augmented operators:

score += 50  // Addition
score -= 10  // Subtraction
score *= 5   // Multiplication
score /= 2   // Division
score %= 3   // Modulus

Example:

score := 100
score += 50
fmt.Println(score) // Output: 150

Try it yourself

package main

import "fmt"

func main() {
	// Starting score
	score := 10
	
	// TODO: Use augmented assignment (+=) to increase score by 5
	
	// Print the final score
	fmt.Println("Final score:", score)
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals