HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to RustVariablesData TypesOperatorsStringsVectors (Vec)Conditions (if / match)Loops (for / while)FunctionsOwnership & Borrowing
REFERENCE
📖 Overview
🖥️ Output
📦 Variables
🔢 Numbers & Math
✍️ String
📋 Vector & HashMap
🔁 Condition & Loop
if / elsematchfor (range)while / loop
🧩 Function
🔑 Ownership & Borrowing
Rust›REFERENCE›Condition & Loop
🔁

Condition & Loop

if, match, and loops.

CommandDescription
if / elseExecutes code based on a condition.
matchPowerful pattern matching.
for (range)Iterates over a range or collection.
while / loopConditional and infinite loops.

if / else

Try it yourself →

Executes code based on a condition.

Syntax

if condition { } else { }

Description

Conditions have NO PARENTHESES, { } blocks are mandatory. if is an expression; it can also yield a value.

Example

fn main() {
    let score = 75;
    if score >= 50 {
        println!("Passed");
    } else {
        println!("Failed");
    }
}

Expected output

Passed

When to use?

Flow branching.

match

Try it yourself →

Powerful pattern matching.

Syntax

match value { x => ..., _ => ... }

Description

A powerful version of switch. _ means 'all other cases' and ALL cases must be handled.

Example

fn main() {
    let day = 2;
    match day {
        1 => println!("Mon"),
        2 => println!("Tue"),
        _ => println!("?"),
    }
}

Expected output

Tue

When to use?

State checking, enum processing.

for (range)

Try it yourself →

Iterates over a range or collection.

Syntax

for i in 1..=n { }

Description

1..n (exclusive of n), 1..=n (inclusive of n). For collections: for x in &v { }.

Example

fn main() {
    for i in 1..=3 {
        println!("{}", i);
    }
}

Expected output

1
2
3

When to use?

Specific repetition, traversing collections.

while / loop

Try it yourself →

Conditional and infinite loops.

Syntax

while condition { }

Description

while loops as long as the condition is true; loop is infinite (exited with break).

Example

fn main() {
    let mut s = 0;
    while s < 3 {
        println!("{}", s);
        s += 1;
    }
}

Expected output

0
1
2

When to use?

Indefinite repetition.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code