• Home
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • React.js
    • Introduction to React
    • React Developer
  • Python
    • Introduction to Python
    • Python Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer
  • Zig
    • Introduction to Zig
    • Zig Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer
  • Interactive Training
  • Pricing
  • Brainstorm
STEMTrainingGrounds
  • Courses
    • Home
    • JavaScript
      • Introduction to JavaScript
      • JavaScript Developer
    • TypeScript
      • Introduction to TypeScript
      • TypeScript Developer
    • React
      • Introduction to React
      • React Developer
    • Python
      • Introduction to Python
      • Python Developer
    • C++
      • Introduction to C++
      • C++ Developer
    • C Language
      • Introduction to C
      • C Developer
    • Rust
      • Introduction to Rust
      • Rust Developer
    • Zig
      • Introduction to Zig
      • Zig Developer
    • Linux Shell
      • Introduction to the Linux Shell
      • Linux Shell Developer
  • Interactive Training
  • Pricing
  • Reading Grounds

Quick Links

  • About Us
  • Pricing
  • Partnership
  • Brainstorm
  • Terms
  • Privacy
  • Refunds
  • Featured on DanielLaunches

Courses

  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • React
    • Introduction to React
    • React Developer
  • Python
    • Introduction to Python
    • Python Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer
  • Zig
    • Introduction to Zig
    • Zig Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer

Newsletter

Subscribe to our free monthly newsletter, for a quick update on Python, JavaScript, and React news

© 2025 - 2026 STEMTrainingGrounds. All Rights Reserved.

Introduction to Rust - Lesson 2

Lesson 2 of 22

Comments

Lesson Progress: 0%

Lesson Progress: 0%
Comments
Lesson Incomplete
← Previous: Hello World
Lesson 2 of 22
Next: Immutable Variables →

Comments are notes in your source code that the compiler ignores — they are written for humans, not the computer. Rust supports three styles of comments: single-line comments with //, block comments with /* ... */, and documentation comments with ///. Comments help you explain what your code does, why you made certain decisions, and how to use your functions. They are invaluable when you revisit your own code months later or when other people need to understand your work. Block comments can span multiple lines, making them useful for temporarily disabling larger sections of code or writing longer explanations. Documentation comments (///) are special because Rust can generate HTML documentation from them using the rustdoctool. As a beginner, you should practice adding comments to your programs — it will make you a clearer thinker and a better communicator.

Code Example
fn main() {
    // I am a comment
    println!("Hello");
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Rust Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • The two forward slashes // start a single-line comment in Rust.
  • Everything after // on the same line is ignored by the compiler.
  • Comments are written for people to read, not for the computer to execute.
  • The println!("Hello") statement runs normally because the comment above it does not affect execution.
  • The output is Hello— the comment produces no output.
Code Example
fn main() {
    /* println!("A");
       println!("B"); */
    println!("Hi");
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Rust Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • /* starts a block comment and */ ends it.
  • Block comments can span multiple lines, making them a good choice for longer explanations.
  • Code inside a block comment is ignored, so println!("A") and println!("B") do not run.
  • Block comments are also useful for temporarily disabling a chunk of code during debugging.
  • The only line that executes is println!("Hi"), so the output is Hi.
Code Example
fn main() {
    println!("A"); // prints letter A
    println!("B"); // prints letter B
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Rust Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • A comment can appear on the same line as code — these are called inline comments.
  • The comment // prints letter A describes what the preceding line does.
  • Inline comments help clarify the purpose of a specific line without cluttering the next line.
  • The code still runs normally: both println! calls execute.
  • The output is A on one line and B on the next line.
Code Example
fn main() {
    // println!("Hidden");
    println!("Visible");
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Rust Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • Placing // at the start of a line of code is called commenting out that line.
  • // println!("Hidden"); prevents the println! from running.
  • Commenting out code is a common technique during debugging to isolate problems.
  • Only println!("Visible") executes, so the output is Visible.
  • To restore the commented line, remove the // prefix.
Code Example
/// Prints a friendly greeting
fn greet() {
    println!("Hello!");
}
fn main() {
    greet();
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Rust Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • Three forward slashes /// create a documentation comment (also called a doc comment).
  • Doc comments appear immediately before the item they describe, such as a function or struct.
  • Rust’s rustdoc tool can read /// comments and generate HTML documentation.
  • Like other comment styles, doc comments are ignored during compilation.
  • The greet() function runs normally and prints Hello!.
Code Example
fn main() {
    // Single line
    /* Block */
    println!("Done");
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

Rust Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • You can freely mix single-line comments // and block comments /* */ in the same program.
  • Both comment styles are completely ignored at runtime — they exist only in the source code.
  • The comment // Single line occupies one line, and /* Block */ appears on its own line.
  • Neither comment produces any output or affects the program’s behavior.
  • The only output is Done from the println! call.

Test Incomplete

Which symbol starts a single-line comment in Rust?

Question #

1/15

Score

0/0 - 0.0 %