Common Programming Concepts

This chapter introduces the core building blocks of Oxide. If you have used other languages, many of these ideas will feel familiar, but the syntax and rules are tailored to Oxide and Rust's safety model.

What You'll Learn

  • Immutable and mutable bindings with let and var
  • Core scalar and compound data types
  • How to define and call functions
  • Comment styles and documentation basics
  • Control flow with if, match, and loops

A Quick Tour

Here is a small program that touches several of the concepts in this chapter:

fn main() {
    let name = "Oxide"
    var counter = 0

    while counter < 3 {
        println!("Hello, \(name)! Count = \(counter)")
        counter = counter + 1
    }

    let grade = 92
    let letter = match grade {
        90..=100 -> "A",
        80..=89 -> "B",
        70..=79 -> "C",
        60..=69 -> "D",
        _ -> "F",
    }

    println!("Final grade: \(letter)")
}

We'll unpack each of these pieces in the sections that follow.