Procedural programming is one of the most common paradigms, especially for learning to program.
• Programs are sequences of instructions
• Uses the three constructs: sequence, selection, iteration
• Code organised into procedures/functions
• Data and procedures are separate
• Top-down design approach
• Examples: C, Pascal, Python (can be procedural)
// Data is separate from procedures
studentScores = [85, 72, 91, 68, 77]
// Procedure to calculate average
function calculateAverage(scores):
total = 0
for each score in scores do
total = total + score
end for
return total / length(scores)
end function
// Procedure to determine grade
function getGrade(average):
if average >= 70 then
return "A"
elseif average >= 60 then
return "B"
elseif average >= 50 then
return "C"
else
return "Fail"
end if
end function
// Main program flow
avg = calculateAverage(studentScores)
grade = getGrade(avg)
print("Average: " + avg + ", Grade: " + grade)
• Small to medium programs
• Problems with clear step-by-step solutions
• Learning to program
• Scripts and automation tasks