PM & AI Chronicles

From Product Thinking to Prompt Engineering – One Tool at a Time

Programming Logic 🧩: How Software Makes Decisions, One Step at a Time 🚦⚖️

This article is part of the Software Development Series — where we break down how software works, how programmers communicate with computers, and what happens behind the scenes when code runs. 👉 — Software Development: Modern Software Basics.

Every computer program, no matter how big or small, is built on simple math and logic. Processors are really good at performing tasks like adding numbers or checking whether one value is greater than another. When a program runs, the processor follows the programmer’s instructions and decides what to do next—almost like solving tiny logic puzzles one after another.

To make these decisions, programs mainly rely on two simple ideas that power almost everything in software:

  • Branching → choosing what to do based on a condition
  • Looping → repeating an action until the work is done

With just these two tools, computers can make smart decisions and handle tasks step by step.

People use branching logic every day without thinking about it. Here’s a simple, universal example:

If the milk has expired, throw it away. Else, keep it in the fridge.

This is branching — a basic if/else decision that helps us choose what to do next. Computers follow the same pattern. They check a condition, decide if it’s true or false, and then take the appropriate action.

Branching uses ideas like if, what if, and else to guide a program through different choices.

Here’s the fridge example written as simple pseudocode:

IF milk_is_expired == True
    THEN throw it away
ELSE
    keep it in the fridge

This is not a real programming language — it simply shows how the logic flows.

Processors compare different types of data during branching.

TypeExplanationExamples
CharA single characterA, m, 5, !
StringA sequence of characters"Hello", "2025", "A"
IntegerWhole numbers without decimals3, 25, 0, −10
FloatNumbers that may include decimals3.14, 6.0, 9.75
BooleanTrue or False valuesTrue, False (may also appear as 1 or 0)

Even if some values look the same, the computer treats them differently because each data type tells the program how to store, read, and use that value. For example:

  • “7” is text (a string) while 7 is a number (an integer).
  • 7 (integer) and 7.0 (float) look similar, but one is used for whole-number math and the other is used for decimal math.
  • “A” (string) and ‘A’ (char) may look identical, but one is stored as a single character and the other as a piece of text.

They look the same to us, but the computer handles them differently based on how they were defined.

Boolean values — True or False — often drive the entire decision. In our example:

IF milk_is_expired == True
    THEN throw it away
ELSE
    keep it in the fridge
  • If the condition is true, one path is taken
  • If it’s false, a different path is taken

This is precisely how software makes decisions.

Programs use identifiers — names given to data. There are two types:

  • Constants: Values that never change during the program. Example based on our scenario:
CONSTANT expired_value = True

This constant stays the same everywhere in the program.

  • Variables: Values that can change. Example:
VARIABLE milk_is_expired 
  • Sometimes the milk is expired, sometimes it’s not, so this value changes.

Here is the fridge example rewritten using both concepts:

CONSTANT expired_value = True
VARIABLE milk_is_expired

IF milk_is_expired == expired_value
    THEN throw it away
ELSE
    keep it in the fridge
  • Constant → the rule
  • Variable → current situation
  • Comparison → true or false
  • Result → decides the action

Branching allows programs to:

  • Compare variables to constants
  • Compare values across different data types
  • Follow a path based on a True/False result
  • Make simple decisions quickly

Branching works well for basic comparisons, but more complex actions may require additional logic tools — leading to the next topic.

As the name suggests, looping is circular logic. Instead of choosing one path and stopping (like branching), a loop repeats the same set of actions again and again until a specific condition changes.

  • A while loop is like the engine of looping — it keeps checking a condition and running again and again until something changes.
  • A for loop is built on the same engine but adds a built-in counter to make repeated tasks easier.

A while loop keeps running as long as a condition remains true. Loops are useful when a program needs to check something repeatedly. for example

If the water in a kettle is not yet boiling, keep heating it. Once it boils, stop. Simple pseudocode:

WHILE water_is_boiling == False
    keep_heating

The loop continues until the water starts boiling.

Loops can also be used to count things. Keep counting from 1 to 5. Pseudocode:

count = 1
WHILE count <= 5
    print count
    count = count + 1

The loop repeats until the number reaches 5.

Loops are powerful, but if not written correctly, they can cause problems. An infinite loop happens when the condition never becomes false, so the loop runs forever.

Example of a bad loop

count = 1
WHILE count <= 5
    print count
    // forgot to increase count!

Since the count never changes, the loop runs forever. In real programs, this can cause the software to freeze or use up all resources.

A for loop is most useful when you already know how many times something needs to happen. Instead of checking a condition over and over like a while loop, a for loop:

  • starts with a beginning value
  • stops at an ending value
  • automatically changes the counter each time

This makes it safer and more predictable than a while loop because the loop is guaranteed to end once it reaches the final number.

Print numbers from 1 to 5.

FOR i = 1 TO 10
    print i

Here, the loop knows exactly:

  • where to start (1)
  • where to stop (10)
  • how to move (+1 each time)

This structure prevents accidental infinite loops and makes counting tasks simple and clean.

A for loop works a lot like a microwave timer:

  • You set it for 30 seconds
  • It counts 1 second at a time
  • When it reaches 0, it automatically stops

You don’t have to tell it what to check each second — the microwave already knows how to count down.

Branching and looping are two of the most important building blocks of programming logic. Branching helps software make decisions by choosing one path or another, while looping allows programs to repeat actions until something changes or a task is complete. Even the most advanced applications rely on these simple ideas behind the scenes.

Once you understand how computers follow conditions, repeat tasks, and react to true or false results, you’re already starting to think the way software thinks. In the next articles, we’ll build on these basics and show how these small logic units combine to form the powerful programs we use every day.

In the next article, we’ll build on this foundation and explore how programmers organize their code—how they structure their work, break big tasks into smaller pieces, and reuse code efficiently to keep programs clean and manageable. 👉 Organizing Code