🌱 Beginner's Guide lesson 1 of 12

Your First Program

Welcome! If you have never written a line of code before, you are in exactly the right place. By the end of this page you will have written, run and changed your very own program. No experience needed, just curiosity.

What is a program?

A program is a list of instructions for a computer, written in a language the computer can understand. The computer reads them from top to bottom and does exactly what they say, one after another.

Computers are very fast but not very clever: they do precisely what you write, even when that's not what you meant. Programming is the art of writing instructions clearly enough that there's no room for confusion.

The language you'll learn here is called steav2. Its keywords (the special words the language understands) are Khmer words written in English letters, so jongyeytha means "print", ber means "if", and so on. Don't worry about memorising them now, we'll meet them one at a time, and each one comes with its English meaning.

The playground

Everything happens right here in your browser. The playground has two halves:

  • The editor on the left, where you type your program.
  • The terminal on the right, where your program's output appears.

To run a program, press the Run button, or hold Ctrl (or Cmd on a Mac) and press Enter.

Every code example in this guide also has its own Run button, so you can try it without copying anything. Go on, click it on the one below!

Hello, world!

It's a tradition that the very first program anyone writes in a new language simply says hello. Here's ours:

[ try-it.sts ]
bongSlanhOun "hello";
jongyeytha "Hello, world!";
[ what it prints ]
Hello, world!

That's two lines, and each one is called a statement: one complete instruction. Let's look at them.

Line 1: bongSlanhOun

Every steav2 program must begin with bongSlanhOun, followed by some text and a semicolon. It doesn't do anything: it's a ceremony, like knocking before you open a door. The text after it can be whatever you like, it's never used. Leave it out and steav2 refuses to run your program at all.

Line 2: jongyeytha

jongyeytha means print. It shows whatever comes after it in the terminal. Here we print the text "Hello, world!". The double quotes " mark where the text starts and ends, and they don't get printed themselves.

The semicolon

Notice that both lines end with ;. A semicolon marks the end of a statement, the same way a full stop ends a sentence. Forgetting it is the most common mistake in the world, so let's make it on purpose and see what happens:

[ x_x broken on purpose ]
bongSlanhOun "oops";
jongyeytha "Hello, world!"
[ what it prints ]
[line 3] Error at end: expected ';' after the value

This is an error message. Errors aren't scary, they're steav2 trying to help. It tells you where it got confused (here, it reached the end of the program, just past the last line, which is why it says line 3) and what it expected (a ;). Reading error messages carefully is a real programming superpower.

More than one line

A program can have as many statements as you like. They run in order, top to bottom:

[ try-it.sts ]
bongSlanhOun "poem";
jongyeytha "Roses are red,";
jongyeytha "violets are blue,";
jongyeytha "I wrote a program,";
jongyeytha "and so can you!";
[ what it prints ]
Roses are red,
violets are blue,
I wrote a program,
and so can you!

Each jongyeytha prints on its own line.

Comments

Sometimes you want to leave a note for yourself (or for other people reading your code). Anything after two slashes // is a comment: steav2 skips it completely.

[ try-it.sts ]
// this whole line is a note for humans
bongSlanhOun "comments";
jongyeytha "I get printed"; // this part is ignored
// jongyeytha "I don't, I'm inside a comment";
[ what it prints ]
I get printed

Comments are also handy for switching a line off without deleting it: just put // in front.

Your turn

  1. Change the hello program so it greets you by name, for example Hello, Dara!. Hint: only the text inside the quotes needs to change.
  2. Write a program that prints three lines about your favourite food. Hint: one jongyeytha per line, and don't forget the semicolons.
  3. Delete the bongSlanhOun line from any program and run it. Read the error message: what does it say?

Solution for exercise 2:

[ try-it.sts ]
bongSlanhOun "food";
jongyeytha "My favourite food is num banh chok.";
jongyeytha "It has noodles and green fish curry.";
jongyeytha "I could eat it every day!";
  • steav2♡ help
  • Y2K✓ ready
  • wasminside
  • .stsvalid

best viewed at 1024x768 ☆ made with ♡ ☆ the reference is steav2's own docs