Ready to begin
No records have been processed. Start with Next step.
A procedure is a named set of steps we can reuse. Think of asking a helper to do one well-defined job. Parameters tell the helper which version of the job to do. A return value brings the answer back.

In SumMarks(F, Mathematics), F is a value used in a comparison with Gender. Mathematics is the name of the field to extract. Inside the procedure, the parameter GenderValue receives F and Field receives Mathematics. X[Field] means “read the field whose name is stored in Field”.
Procedure SumMarks(Rows, GenderValue, Field)
Sum = 0
for each row X in Rows {
if (X.Gender == GenderValue) {
Sum = Sum + X[Field]
}
}
return Sum
End Procedure
GirlsMaths = SumMarks(Scores, "F", "Mathematics")
BoysMaths = SumMarks(Scores, "M", "Mathematics")Read the current record, check the explanation, and watch the variables. Use Back to revisit any step.
Ready
No records have been processed. Start with Next step.
Start at the first step. Watch the current row and the values we remember.
| Call | Returned value |
|---|---|
| SumMarks(Scores,F,Mathematics) | 951 |
| SumMarks(Scores,M,Mathematics) | 1220 |
| SumMarks(Scores,F,Chemistry) | 1064 |
| SumMarks(Scores,M,Chemistry) | 1250 |
Sum starts at zero on every call. Changing parameters does not require rewriting the loop. return Sum sends the computed number to the caller; writing it into GirlsMaths preserves it for later. Equal code does not mean equal answers when the parameters differ.
The groups contain 13 F and 17 M records. Raw sums alone do not establish which group has a higher average. Divide each group sum by its own count for that question.
Which argument is an attribute name in SumMarks(F,Chemistry)?
Chemistry. F is the category value to compare.
What does return Sum do?
It sends the computed Sum back to the code that called the procedure.
Should Sum keep its value from the previous call?
No. Each new sum computation initializes its own Sum to zero.
Do larger total group marks necessarily mean a larger average?
No. Groups can have different numbers of records.