Main Content

Flowchart to program - learning to program with Well House

Archive - Originally posted on "The Horse's Mouth" - 2012-10-14 09:14:28 - Graham Ellis

Drawing a flowchart is how many people understand a process; it's something that's been used in schools and textbooks for many generations, and it provides a graphic representation of choices and actions that most people find easy to follow.

For newcomers to programming, such as on my Learning to program in Python course early last week, writing their first loops and conditions can be daunting - and yet they'll very often be familiar with a flowchart.

But it turns out that a program with a conditional in it is no more than a flowchart converted to a textual representation. Rather than a diamond box, the word if is used, and that may be followed by the contents of the diamond box in brackets - the exact syntax used will depend on the language.

Below the diamond box on a flowchart, you'll typically have rectangular boxes side by side saying what to do if the condition is true ("yes"), and what to do if the condition is not true ("no"). In a program, you can't have two pieces of code side by side, so you'll write them one above the other and indicate somehow (it depends on the language) where one of the blocks ends and the other starts.

Let's take that graphic representaton from the flowchart and show you the structure in PHP or Perl:

  if (condition) {
    true action
  } else {
    false action
  }


and in Python:

  if condition:
    true action
  else:
    false action


Our next "learning to progam in ..." courses are scheduled as follows:

Learning to program in Ruby - from 22nd October 2012 [link]
Learning to program in PHP - from 4th November 2012 [link]
Learning to program in Python - from 3rd December 2012 [link]
Learning to program in Perl - from 10th December 2012 [link]

If you want to learn to program in Lua, Tcl, C or C++, we offer those courses too, though remaining availablity in 2012 is limited. A full schedule, showing all courses at least 6 months ahead, is available [here].