Loop, Conditional, Modulus

Part of Golang Mastery course

~15 min read
Interactive
Hands-on
Beginner-friendly

Use the modulo operator % and a for loop and if statement to print out all the even numbers from 1 to 100

example.go
package main
 
import (
string">"fmt"
)
 
func main() {
for i := 1; i <= 100; i++ {
if i%2 == 0 { string">"comment">// try changing the number to 3, 4, etc.
fmt.Println(i)
}
}
}
 

playground

Your Progress

21 of 103 modules
20%
Started20% Complete
Previous
SpaceComplete
Next