Cambridge IGCSE and O Level Programming Book
The pseudocode for this function and its call from the main program are as shown here:
FUNCTION multiples(number) FOR i = 1 TO 5 OUTPUT number * i NEXT ENDFUNCTION CALL multiples(10) This uses a FOR loop. FOR loops are introduced more fully in Chapter 7. KEY TERMS
Task
FOR loop: A type of iteration that will repeat a section of code a known number of times.
26
Task 1 Create a pseudocode algorithm for an amended version of the Multiples procedure that accepts two parameters: a number to use as the multiplier and another to indicate the maximum number of multiplications required.
Functions That Return Values to the Calling Routine
DeMO Task
Often programmers write functions that are required to produce answers for repetitive tasks and then return those values to the main program. For example, it might be necessary for a program to calculate the circumference of several circles from their radii.
Circumference A function is required that will be passed the radius of a circle and return the circumference.