Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Your First Program · Lesson 6 of 9

Comments

A free lesson from Swipe Coding · Go, level 2 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
Comments are notes for humans — the Go compiler skips right past them. 🐹

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 code
Both comment styles are valid: a // comment on its own line, and a // comment trailing after real code on the same line.

A 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")
Everything between /* and */ is ignored, so only "Still runs" is printed when this code executes.
Quick check

Which comment style can span multiple lines in Go?

Fill in the blank

In Go, everything after ____ on a line is ignored by the compiler, up until the end of that line.

🤖
This convention is how tools like godoc generate documentation automatically. 📚

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.

True or false

Comments are compiled into the final executable and can slightly affect how fast a Go program runs.

Chapter quiz

Your First Program

10 questions · pass with 60% — just like in the app.

Quick check

Which package name marks a Go file as a runnable program rather than a library?

True or false

A Go program must contain a function called main() inside package main.

Fill in the blank

A Go file that imports "fmt" but never uses it anywhere causes a ____.

Quick check

Which command compiles and runs a Go file in a single step?

True or false

fmt.Println automatically adds a newline at the end of its output.

Fill in the blank

The format verb ____ inserts a value formatted as an integer inside fmt.Printf.

Quick check

Which function prints without adding a trailing newline?

True or false

A /* */ block comment can span multiple lines, while a // comment only extends to the end of its line.

Fill in the blank

The format verb ____ prints the Go type of a value, which is useful for debugging.

Quick check

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 →