Lesson 7

Comparison: дуруст and нодуруст

Comparison: дуруст and нодуруст

In this lesson: you will compare values and meet logical values.

The whole lesson on one page

Comparison: дуруст and нодуруст

In this lesson: you will compare values and meet logical values.

Logical values

The answer to the question "is it true that ...?" is дуруст (yes, true) or нодуруст (no, false). These values are called logical (мантиқӣ):

1чоп(5 > 3);
2чоп(2 > 7);
3тағ офтобӣ = дуруст;
4чоп("Имрӯз офтобӣ:", офтобӣ);

Comparison signs

SignMeaningExampleResult
>greater than5 > 3дуруст
<less than5 < 3нодуруст
>=greater than or equal to5 >= 5дуруст
<=less than or equal to4 <= 3нодуруст
===equal to2 + 2 === 4дуруст
!==not equal to3 !== 3нодуруст
1тағ рақам = хонданиРақам();
2чоп("Мусбат:", рақам > 0);
3чоп("Ҷуфт:", рақам % 2 === 0);
4чоп("Даҳ:", рақам === 10);
Input
10

= and ===

  • = is assignment: тағ х = 5; gives х the value 5.
  • === is comparison: х === 5 asks "is х equal to five?".

Do not mix up these two signs. If you write = in a condition, the playground will warn you.

Comparing strings

1тағ ҷавоб = хондан();
2чоп(ҷавоб === "Душанбе");
Input
Душанбе

Two strings are equal only if all their letters are the same: "душанбе" is not equal to "Душанбе".

Task: Greater?

Read two numbers and print the result of the comparison а > б: дуруст or нодуруст.

Input: Two numbers.

Output: дуруст or нодуруст

Task: Even?

Read a number and print whether it is even: дуруст or нодуруст.

Input: One number.

Output: дуруст or нодуруст

Task: Password

Read a word and print whether it matches the password сомон: дуруст or нодуруст.

Input: One word.

Output: дуруст or нодуруст