Reference

Programming languages

Choose TypeScript, Go, Rust or C++ and find syntax, everyday APIs, standard libraries and tools in one place.

Scope and conventions

TypeScript/Node, Go 1.23+, Rust 2024 and C++23: from a first CLI to files, JSON, HTTP, concurrency and testing. Complete programs are labeled; other examples identify their surrounding code/imports. Optional libraries and version requirements are named in each entry.

Control flow

Branch and exit early

C++

if tests a value convertible to bool. Built-in &&/|| short-circuit and return bool: && skips the right side when the left is false; || skips it when true. Overloaded operators do not short-circuit. condition ? a : b evaluates only the selected branch.

Fragment

Fragment inside a function.

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const int n = 4;
if (n == 0) {
    // zero
} else if (n > 0) {
    // positive
}

Loop over values

C++

A range-for visits elements; a three-part for can count or repeat indefinitely. String iteration visits char units, not decoded Unicode characters. break exits the loop.

Fragment

Header at file scope; loop statements inside a function.

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
#include <string>

for (char ch : std::string("west")) {
}

for (int i = 0; i < 2; ++i) {
}

for (;;) {
    break;
}

Select a case or match a pattern

C++

switch works with suitable integral/enum conditions, not ordinary strings. Cases can fall through without an exit; [[fallthrough]] documents intent. C++23 does not have Rust-style general match syntax.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
enum class Mode { Read, Write };
Mode mode = Mode::Read;

switch (mode) {
case Mode::Read:
    break;
case Mode::Write:
    break;
}

Repeat while a condition holds

C++

while checks before the body; do…while checks after it. for (;;) repeats indefinitely. break exits the nearest loop/switch; return exits the function.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

main.cpp
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
int n = 3;

while (n > 0) {
    --n;
}

do {
    ++n;
} while (n < 1);