Comments
A free lesson from Swipe Coding · Go, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
A line comment starts with // and runs to the end of that line. The compiler ignores everything after the //, which makes it a quick way to leave a short note for yourself or anyone else reading the code.
// This line explains what happens next
fmt.Println("Hello!") // this comment trails the codeA block comment starts with /* and ends with */, and can span as many lines as you want in between. Block comments are handy for longer explanations, or for temporarily disabling a whole chunk of code without deleting it.
/*
This entire block
is ignored by the compiler,
no matter how many lines it spans.
*/
fmt.Println("Still runs")Which comment style can span multiple lines in Go?
In Go, everything after ____ on a line is ignored by the compiler, up until the end of that line.
There's also a convention worth knowing early: a comment written directly above a function or package, starting with that function or package's own name, is treated as documentation by Go's tooling. Following this pattern consistently means your code can generate readable documentation automatically, without any extra effort.
Comments are compiled into the final executable and can slightly affect how fast a Go program runs.
Your First Program
10 questions · pass with 60% — just like in the app.
Which package name marks a Go file as a runnable program rather than a library?
A Go program must contain a function called main() inside package main.
A Go file that imports "fmt" but never uses it anywhere causes a ____.
Which command compiles and runs a Go file in a single step?
fmt.Println automatically adds a newline at the end of its output.
The format verb ____ inserts a value formatted as an integer inside fmt.Printf.
Which function prints without adding a trailing newline?
A /* */ block comment can span multiple lines, while a // comment only extends to the end of its line.
The format verb ____ prints the Go type of a value, which is useful for debugging.
What must you add manually when using fmt.Printf if you want the output to end on a new line?
Keep your streak going in Swipe Coding
Swipe through every level of Go on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →