Lesson 1

Your first program

Your first program

In this lesson: you will write your first program, run it, and use чоп to show text and numbers on the screen.

The whole lesson on one page

Your first program

In this lesson: you will write your first program, run it, and use чоп to show text and numbers on the screen.

What is a program?

A program is a list of commands for the computer. The computer runs them one by one, from top to bottom.

The playground

We write and run programs in the playground (майдони озмоиш): https://lindentechde.github.io/Somon-Script/. It opens in the browser, and you do not need to install anything. You write the program on the left. On the right are "Вуруд" ("input") and "Натиҷа" ("output"). The ▶ Иҷро ("Run") button runs the program. The page is in Tajik and Russian.

The чоп command

1чоп("Салом, ҷаҳон!");
  • чоп ("print") shows what is inside the brackets in "Натиҷа".
  • Text is written in quotes "…". In programming, a piece of text is called a string (сатр).
  • Every command ends with ;.

Several lines and numbers

1чоп("Ман барномасозиро меомӯзам.");
2чоп("Ин барномаи аввали ман аст.");
3чоп(2026);
4чоп(2 + 3);
5чоп("2 + 3");
  • The commands run in the order in which they are written.
  • Numbers are written without quotes. чоп(2 + 3) prints the answer: 5. But чоп("2 + 3") prints the text just as it is: 2 + 3.

Several values on one line

1чоп("Ҷавоб:", 6 * 7);
2чоп("Ман", 13, "сола ҳастам");

Values separated by commas are printed on one line, with a space between them: Ҷавоб: 42.

Common mistakes

  • Forgetting to close the quote: чоп("Салом);
  • Writing Чоп or chop. Capital and small letters are different: only чоп works.
  • Forgetting to close the bracket: чоп("Салом";

If you make a mistake, the playground tells you where it is. In the next lesson, we will learn to read these messages.

Task: Hello, world!

Write a program that prints the line Салом, ҷаҳон!.

Input: None.

Output: Салом, ҷаҳон!

Task: Three lines

Print these three lines exactly:

Ман барномасозиро меомӯзам.
Барнома аз фармонҳо иборат аст.
Ҳар фармон бо нуқтавергул тамом мешавад.

Input: None.

Output: The three lines above.

Task: A little house

Use чоп to draw this picture. The spaces at the start of the lines matter too.

    *
   ***
  *****
 *******
  |   |
  |___|

Input: None.

Output: The picture above.