Lesson 1 of 28
Lesson Progress: 0%
Zig is a general-purpose programming language that gives you full control over your code. Every Zig program starts by importing the standard library with @import("std") and defining a main function. The pub fn main() void line is the entry point where execution begins. To display text, use std.debug.print which takes a format string and an empty tuple .{}. This lesson will teach you how to write and run your first Zig programs step by step.
const std = @import("std");
pub fn main() void {
std.debug.print("Hello, world!", .{});
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
const std = @import("std"); brings in Zig's standard library so you can use its functions.pub fn main() void declares the main function that runs when the program starts.std.debug.print prints text to the terminal for debugging and learning."Hello, world!\n" is the string to print, and \n moves to a new line..{} provides no extra values to insert into the format string.const std = @import("std");
pub fn main() void {
std.debug.print("Hello from Zig!", .{});
std.debug.print("Welcome to the language.", .{});
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
std.debug.print multiple times to print several lines.std.debug.print prints one line of text.pub fn main() void to start.const std = @import("std");
pub fn main() void {
const msg = "Hello, world!";
std.debug.print("{s}", .{msg});
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
const msg = "Hello, world!"; stores the message in a constant variable.{s} in the format string is a placeholder for a string value..{msg} passes the variable msg to fill the placeholder.const std = @import("std");
pub fn main() void {
const name = "Zig";
const year = 2024;
std.debug.print("Hello {s} in {d}!", .{ name, year });
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
{s} for strings and {d} for numbers..{ name, year } provides values in the same order as the placeholders.const declares a variable that cannot change after it is set.{s} for strings and {d} for integers in format strings.const std = @import("std");
fn greet() void {
std.debug.print("Greetings from Zig!", .{});
}
pub fn main() void {
greet();
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
fn functionName() void { ... }.greet() is a custom function that prints a message when called.main function calls greet() to run its code.const std = @import("std");
pub fn main() void {
std.debug.print("Hello, {s}!", .{"world"});
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
std.io.getStdOut().writer() gets a writer for the standard output.writer.print() method prints formatted text like std.debug.print.catch {} handles any errors that might occur during printing.Test Incomplete