Programs are created using common building blocks, known as programming constructs. These programming constructs form the basis for all programs and are also used in algorithms.
selectionA decision within a computer program when the program decides to move on based on the results of an event. and iterationThe repetition of a block of statements within a computer program. constructs can be nestingIncluding one programming construct within another. within each other. Any combination of selection and iteration is possible. So, for example, a for nextloopThe repetition of an activity within a computer program. might have an if 鈥 else 鈥 end if selection within it.
This example has an if 鈥 else 鈥 end if construct nested within another if 鈥 else 鈥 end if construct:
age is integer
input 鈥淗ow old are you?鈥, age
if age >= 16
output 鈥淵ou are old enough to drive a moped!鈥
if age >= 17
output 鈥淵ou are old enough to drive a car!鈥
聽聽聽聽end if
else
output 鈥淐ome back when you are older!鈥
end if