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 + 50Use the += operator:
score := 100
score += 50
fmt.Println(score)Output:
150Other augmented operators include -=, *=, /=, and %=:
count := 10
count *= 5 // Same as: count = count * 5
fmt.Println(count)Output:
50Challenge
BeginnerIn 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.
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)
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Comparison & Logical Operators
Comparison Operators - Part 1Comparison Operators - Part 2Logical AND OperatorLogical OR OperatorLogical NOT OperatorOperator Precedence BasicsRecap - Making Comparisons7Control Flow: Loops
What The `for` Loop ExplainedFor Loop - BasicFor Loop - Condition OnlyThe `break` KeywordThe `continue` KeywordNested LoopsRecap - Repeating Actions2Variables and Basic Data Types
What is a variableType Inference with `:=`Integers (int)Floating-Point NumbersBooleansStringsZero ValuesConstantsNaming ConventionsRecap - Variables and Types5Basic Input/Output
Formatted OutputFormat VerbsPrinting TypesGetting Basic User InputRecap - Input and Output8Functions
Understanding FunctionsDeclaring a FunctionCalling FunctionsFunction ParametersReturning a Single ValueReturning Multiple ValuesNamed Return ValuesFunction Scope BasicsRecap - Creating Reusable Code3Basic Operators
Arithmetic OperatorsDivision OperatorThe Modulo OperatorAssignment OperatorAugmented Assignment OperatorsIncrement and DecrementRecap - Calculations6Control Flow: Conditionals
The `if` StatementThe `else` KeywordThe `else if` KeywordVariable Shadowing in `if`Initializing VariablesThe `switch` StatementSwitch with ExpressionsSwitch without ExpressionThe `fallthrough` KeywordRecap - Making Decisions