Drill 18: Why this way — Variables and control flow
Explain why the example is written this way rather than another way.
What you will be able to do
- Explain why the example is written this way rather than another way.
Practice task
Explain why the example is written this way rather than another way.
package main
import "fmt"
var maxLessons = 14
func main() {
var minutes int
var published bool
fmt.Println(minutes, published)
minutes = 12
published = true
title := "Variables and control flow"
if published && minutes >= maxLessons {
fmt.Println(title, "is long")
} else {
fmt.Println(title, "is short")
}
switch minutes {
case 5:
fmt.Println("quick")
case 12:
fmt.Println("steady")
default:
fmt.Println("other")
}
for i := 1; i <= 3; i++ {
fmt.Println("lesson", i)
}
}Your turn
EasyWrite your answer
Explain why the example is written this way rather than another way.
TEXT · starter
Your answer…Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.