5. Flowcharts & Pseudocode

Flowcharts & Pseudocode

Before writing code, experienced programmers plan their logic in a form that is quick to draft and easy to check. Two planning tools dominate: flowcharts (visual) and pseudocode (textual). Both let you design an algorithm without worrying about the exact rules of a programming language.

Flowchart Symbols

A flowchart is a diagram where each shape has a standard meaning and arrows show the order in which steps happen. The five shapes you will use most often:

Terminator Start or End of the process Process An action or calculation step Decision A yes/no question that branches Input / Output Read data in or display results Conn. Connector: joins parts of a flowchart together

When to Use Pseudocode

Pseudocode is a way of writing an algorithm in plain, structured English that resembles code but ignores a language's strict punctuation. It is ideal when the logic has lots of steps, loops, or calculations that would make a flowchart sprawl across the page. Flowcharts shine for showing branching and flow at a glance; pseudocode shines for detailed step-by-step logic. Many programmers sketch a flowchart first for the big picture, then write pseudocode for the tricky parts.

Side-by-Side Example: Is a Number Positive, Negative, or Zero?

The same algorithm expressed both ways. First, pseudocode:

INPUT n
IF n > 0 THEN
    OUTPUT "Positive"
ELSE IF n < 0 THEN
    OUTPUT "Negative"
ELSE
    OUTPUT "Zero"
END IF

And the matching flowchart:

Input n n > 0 ? Output "Positive" n < 0 ? Output "Negative" Output "Zero" yes no yes no

Good Habits

  • Keep each step small and do exactly one thing.
  • Make every decision a clear yes/no question.
  • Check that every path eventually reaches an end.
  • Walk through your design with sample inputs (a "dry run") before coding.

Planning with flowcharts and pseudocode costs a few minutes but saves hours of confused debugging. It is the professional habit of thinking before typing.