Nesting
nestingIncluding one programming construct within another. is when one programming construct is included within another. Nesting enables powerful yet simple programming. It reduces the amount of code needed, while making it simple for a programmer to debugThe process of finding and correcting programming errors. and edit.
Nested selection
When using selectionA decision within a computer program when the program decides to move on based on the results of an event., the number of possible paths at a decision point can be increased by including one selection within another.
This pseudocode Also written as pseudo-code. A method of writing up a set of instructions for a computer program using plain English. This is a good way of planning a program before coding. program uses nested selection:
SEND ‘How old are you?‘ TO DISPLAY RECEIVE age FROM (INTEGER) KEYBOARD IF age > 16 THEN SEND ‘You are old enough to drive a car and ride a moped’ TO DISPLAY ELSE IF age = 16 THEN SEND ‘You are old enough to ride a moped!’ TO DISPLAY ELSE SEND ‘Come back when you are older!’ TO DISPLAY END IF END IFHere, there are two conditions that may be tested, resulting in three possible paths to follow. The second condition is only tested if the result of the first test is FALSE.
Nested selection can be built up over and over to include many possibilities and paths for a program to follow. It enables complex decisions to be made.
Nested iteration
iterationThe repetition of a block of statements within a computer program. can also be nested. This pseudocode Also written as pseudo-code. A method of writing up a set of instructions for a computer program using plain English. This is a good way of planning a program before coding. program uses two count-controlled loopingRepeatedly executing a section of code. - one within another - to print out the times table for all numbers from one to ten:
FOR x FROM 1 TO 10 DO FOR y FROM 1 TO 10 DO SET result TO y * x SEND y & " * " & x & " = " & result TO DISPLAY END FOR END FORFor every iteration of x, y is iterated ten times.
This program uses condition-controlled WHILE loops, one within another, to print out the times table for all numbers from one to ten:
SET x TO 1 SET y TO 1 WHILE x < 11 DO WHILE y < 11 DO SET result TO y * x SEND y & " * " & x & " = " & result TO DISPLAY y = y + 1 END WHILE SET y TO 1 SET x TO x + 1 END WHILEFor every iteration of x, y is iterated ten times.