AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Contents · Computing

The branching algorithm: “if” and the condition

Lessons 25–27 · 3 lessons · F.M. Zakirova, M.R. Zakirova. Informatics and Information Technology Grade 2. Novda Edutainment, 2024
25

Branching algorithm

Textbook: pp. 66–68
GoalKnow what a branching algorithm is: the action depends on a condition (if ... then we do ...).
New words
if · agarcondition · shartbranching · tarmoqlanishdecision · qaror
Explanation

In life we often decide according to the situation. If it is cold outside, we put on a warm jacket. If it is warm, no jacket is needed. An algorithm whose actions depend on a condition is called a branching algorithm. In words we write it with “if”: “If yes — do this, if no — do that”.

StartIs it cold outside?yesnoput on a warm jacketno jacket neededEnd
StartIs it raining?yesnoTake anumbrellaGo without oneEnd

Answer the question: Yes or No

🚪 Where will I use this?
In real life

If a door is closed, we knock. If it is open, we go in.

Try it today

Say one sentence with “If ... then ...”.

Worked examples
At a traffic light: if the green light is on, we cross; otherwise we stop and wait.
Startnumberdoes it divide by 2?yesnoevenoddEnd
If a number divides by 2 it is even, if not it is odd. 8 is even, 9 is odd.
Class activity

“If it is true”: the teacher states a condition and children act. “If your clothes are blue, stand up. If not, clap.” Each child does just one action, depending on the condition.

Practice
1
Algorithm: if a number divides by 2 it is even, otherwise odd. What kind of number is 14?
2
By the same algorithm, what kind of number is 17?
3
Finish the sentence “If it rains — ...”
Story of the Week · The Khwarizmi WayAfter the holidayClose the week: all of this week’s subjects in one storyRead →