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.
Join the Conversation