Control Structures in Programming

An Explanation of the Three Basic Structures Found in Programs

7 Comments
Join the Conversation
Program Code - Mario Alberto Magallanes Trejo
Program Code - Mario Alberto Magallanes Trejo
For programmers it is essential to understand the three control structures, sequence, repetition and selection which are the elementary building blocks for all programs.

Beginners can find Programming very confusing, Just like any other subject, there are a lot of new concepts to understand and lots of new terminology to learn. One of the most basic concepts in programming is control structures.

There are three control structures and all programmers must learn what they are and how they can be used. These three basic structures can be used to develop any kind of program and they are explained below.

Sequential Programming

The most straightforward control structure is the sequence. A list of what to do, step by step.

For example:

  • do the first thing
  • do the next thing
  • do another thing

In pseudocode:

  • Declare a variable called count
  • Set count to 1
  • Write out the value of count

Repetition in Programming

Repetition is also called iteration and is used when something is repeated over and over again, so anything where the program goes round in a loop. Typically programmed using code such as WHILE, REPEAT and FOR statements.

For example:

  • Do the first thing
  • While (some condition is TRUE)
    • Do b
    • Do c
  • Do the next thing

In pseudocode:

  • Set count to 0
  • WHILE (there are items in a pile)
    • Increase count by 1
  • Write out the number of items

Another example: to write out numbers 1 to 10

  • FOR count = 1 to 10
    • Write out count
  • Write out ‘finished’

NOTE: a FOR loop is used when it is known exactly how many times to go round the loop

Selection in Programming : Making Decisions

Selection is used to make a decision to go down one path or another, often programmed using code such as an IF statement, or a CASE statement.

For example: To Pack my bag for work)

  • Pack my PC
  • Pack my money
  • If it's raining
    • Pack my coat

In pseudocode:

  • Work out total cost
  • If (total cost > £10) THEN
    • Write out ‘no delivery charge’
  • ELSE
    • Write out ‘£5 delivery charge’
  • Write out ‘thankyou’

Another example using a CASE:

  • Write out the day
  • CASE (day)
    • Monday: write out ‘first working day of the week’
    • Friday: write out ‘last working day of the week’
    • Saturday: write out ‘the first day of the weekend’
    • Sunday: write out ‘the second day of the weekend’
  • ENDCASE

Sometimes there is confusion between the Repetition and Selection statements, as both use a condition. A condition is a test, resulting in true or false. One way of describing the difference is that when making a selection, the condition is only ever tested once. When used in repetition, the condition is tested a number of times, every time the program decides whether to loop.

Beginners who take the time to learn the basic building blocks of programming will find coding in new languages easier and developing computer programs requires an understanding of the three basic control structures outlined above.

Dawn Brewer, Writer, Dawn Brewer

Dawn Brewer - I have a portfolio career - as a writer, management consultant, instructor and coach - after twenty years in the corporate world. My ...

rss
Advertisement
Leave a comment

NOTE: Because you are not a Suite101 member, your comment will be moderated before it is viewable.
Submit
What is 5+5?

Comments

Jun 24, 2009 10:30 PM
Guest :
I found this article very useful and still a little confusing because the pseudo codes are what I am not used to.
Sep 1, 2009 10:41 AM
Guest :
i am taking a programming class and you have clarified some areas up for me...thank you!!
Jun 30, 2010 3:58 AM
Guest :
Good article, got all the info I needed^^
Jul 24, 2010 10:05 PM
Guest :
i need the meaning , types and synax of the control string.. this article make me confuse however there arte some which can i understand.tnx..
Jan 27, 2011 1:30 AM
Guest :
Very useful
Mar 29, 2011 12:24 AM
Guest :
This was extremely helpful. I am in a beginning programming and logic course and this article explained clearly and concisely what my prof. could not. Thank you.
Sep 28, 2011 6:28 PM
Guest :
thanks for the help :)
7 Comments
Advertisement
Advertisement