1. Introduction

Welcome! This is a series of articles with the goal of teaching you programming using the Odin programming language. I’m going to do my best to cover all aspects of the core language here. If you are already familiar with the basics and want to learn about how to use some of the vendor packages, I have plans for that as well. I’m working on raylib content to begin with but I have plans to add lessons on other vendor libraries later. ...

May 8, 2025

2. Preparing to Program in Odin

Before you start programming, you need to make sure you have the tools you need. We are only going to install what we need to get started. Later, we can install other packages when the need for them arises. To get started, you will need: the Odin compiler a text editor or an IDE, whichever you prefer a terminal application Getting Odin The first thing to do is install Odin. How to do this will vary a bit depending on which operating system you are using. I mostly use Linux and BSD systems, and my primary work machine has Fedora on it. The Getting Started page on the Odin website shows you how to install Odin for your programming language. ...

May 10, 2025

3. First Programs

I’m going to assume that you have Odin installed at this point. We are going to jump straight into writing our first little program; a program that just prints a message to the terminal and exits. It’s probably the simplest program we can write, so it’s a quick way to test that our setup is working properly. Then we can start asking some basic questions. Create a directory (folder). You can call it hellope, or some other name, if you wish. I personally avoid spaces in file and directory names and prefer to not use uppercase letters, for most part. In the folder create a file that ends with .odin. I will call it main.odin, but hellope.odin works just as well. ...

May 8, 2025

4. Variables and Conditionals

Variables are a requirement for us to be able to write programs that can do something useful. So let’s try to get an understanding of what they are. But before that, let’s write a bit of code as it’s easier to reason about something you’ve at least seen before. First, let’s rewrite the program we learned in the last lesson, but using a variable to hold the greeting. Remember to create a new directory and switch into the new directory to create a new file named something that ends in .odin. In this file, write the following code. ...

May 8, 2025

5. Command Line Args

In the last lesson, we learned what variables are and how to use them. We also briefly touched upon the if statement. In this lesson, we are taking one step further towards writing dynamic programs by accepting external input. This could come in many forms: the user could be prompted to type something that gets captured into a variable the input could come from a file that is read the input could come from another program on your computer, via a pipe (something we will look at later) the input could come from command-line arguments Allowing the user to pass command-line arguments is probably the simplest of those, so that is what we are going to look at first. ...

May 8, 2025

6. Converting Strings to Other Types

We ended the last lesson by trying to write a program that adds together numbers that were passed in by the user as command-line arguments. This didn’t work, because command-line arguments are strings and the + operator is not supported for strings. String to integer conversion with type casting Put simply, type casting is converting the value of a variable from one type to another. For instance, converting a string to an int. We are going to need a new package, called strconv which exists in the core collection. The best way to figure out how something works is to try it out in a program. ...

May 13, 2025

7. Loops

You have already used the for loop. Here we are going to look at it in a bit more detail and figure out a few other ways in which we can use it. A simple counter We want to count from 1 to 10. The following will do just that. 1 2 3 4 5 6 7 8 9 package main import "core:fmt" main :: proc() { for i in 1..=10 { fmt.println(i) } } The 1..=10 is called a range and it means from 1 to 10, inclusive. If we wanted to exclude 10, we would use 1..<10 instead. Modify the program above to verify that actually is the case. ...

May 16, 2025

8. User Input

You already know how to get user input via command-line arguments. In this lesson we are going to look at another way of getting input from the user: to prompt them for it from within the program itself. Prompting the user for input As I’ve mentioned earlier, the terminal is connected to 3 standard communication channels: standard input, standard output and standard error. We have used the two output channels already. Now we are going to read in user input via standard input. ...

May 8, 2025

Answers to Exercises

The answer section is a work in progress. I am working on providing answers to every exercise but this takes time. Thank you for your patience. ...

May 10, 2025