Skip to main content
Informatik.uz
Chapter 1. Types of Algorithms

Branching Algorithms and Conditions

Sometimes the action has to be chosen depending on the situation. We study conditions, full and short branching, and build an algorithm that finds the larger of two numbers.

Topic 1 of 111 min readUpdated October 27, 2026
All topics (1 of 11)

In life, many things depend on the situation: if it rains, we take an umbrella, and if it does not, we leave it at home. In such cases the algorithm is branching: it checks a condition and, depending on the result, chooses one of two paths. A condition is a statement that can be true or false.

There are two kinds of branching. In full branching, “if the condition is true, one action is performed, otherwise another action is performed”. In short branching, the action is performed only when the condition is true, and otherwise nothing happens. In a flowchart, the condition is written inside a diamond with two arrows labeled “yes” and “no” leaving it.

Example: finding the larger of two numbers. The numbers a and b are entered, and then the condition a > b is checked. If it is true, the answer is a; otherwise the answer is b. Complex conditions are built with the words “and”, “or” and “not”: for example, “the number is greater than 10 and less than 20”.

Key takeaways

  • In a branching algorithm, one of two paths is chosen depending on a condition.
  • A condition is a statement that is either true or false.
  • Branching can be full (“if … otherwise …”) or short.
  • In a flowchart, the condition is shown in a diamond with “yes” and “no” arrows.
  • Complex conditions are built with “and”, “or” and “not”.

Practice tasks

  1. Draw a flowchart for the algorithm “If it is cold outside, put on warm clothes, otherwise put on light clothes”.
  2. Build a flowchart for an algorithm that decides whether an entered number is positive, negative or zero; use two conditions one after another.
  3. Create an algorithm that finds the larger of two numbers and run it by hand for a = 7 and b = 12: which arrow do you follow, and what is the answer?

Review questions

Test yourself: think first, then reveal the answer.

  1. 1What is a condition?
    A statement that can be true or false, for example a > b.
  2. 2How do full and short branching differ?
    In full branching a separate action is performed whether the condition is true or false; in short branching the action is performed only when the condition is true.
  3. 3Which shape shows a condition in a flowchart?
    A diamond, with “yes” and “no” arrows leaving it.

0 of 11 topics completed

Sign in to mark
Informatika 7-sinf darsligi muqovasi
In the textbookInformatics — Grade 7