Making decisions
ከሆነ, ግን, አለበለዚያ — and the word order that matters
A program does not always run straight down. Sometimes you need to say "if this is true, do that".
ትልቅ ሰው
The condition comes first
This is the one thing about Ahadu most worth understanding. English-based
languages say if age > 18 — keyword first, condition second. Amharic does
not say it that way. It says "ዕድሜው ከ18 በላይ ከሆነ" — the condition, then
the word that makes it a question.
Ahadu follows the Amharic:
ዕድሜ > 18 ከሆነ፦Read aloud, the code is the sentence. ፦ is the Ethiopic colon, and it means
"what follows belongs to this".
This is also the single biggest fix in version 2. Version 1 parsed these clauses the other way round, so conditions ran inverted — and 7,600 passing tests never noticed, because none of them ran a whole program and looked at what it printed.
Two ways
What if the condition is not true? አለበለዚያ — "otherwise".
ልጅ
More than two
ግን adds another condition. Note the shape: ግን leads, then the condition,
then ከሆነ.
ሲ
They are tested top to bottom. The first true one runs and the rest are never looked at.
Comparisons
| Operator | Meaning |
|---|---|
> |
greater than |
< |
less than |
>= |
greater than or equal |
<= |
less than or equal |
== |
equal |
!= |
not equal |
= and == are different. = stores a value; == compares two.
Joining conditions
እና (and), ወይም (or) and አይደለም (not) combine conditions.
ብድር ይፈቀዳል
Indentation counts
The lines after ፦ must be indented. Everything indented belongs to the
condition.
ጥንድ ነው
ይህም የሁኔታው አካል ነው
ይህ ግን ሁልጊዜ ይጻፋል
Exercise
Write a program that says whether a number is even or odd.
Show the answer
7 ጎዶሎ ነው