Nesting
of selection and iteration statements
Due to the facility of providing compound
statements to be executed in selection and iteration statements, it is
possible to nest one control statement within another.
Thus one could have a selection statement
within a selection statement, or an iteration statement within an
iteration. Or a selection within an iteration. And so on.
There is no limit to the level of nesting of these control statements.
One pseudocode example is as follows:
if(
test1 )
{
statementA;
if( test2 )
statementB;
statementC;
}
In the above example, if test1 is false,
none of these statements will be executed.
If test1 is true, statementA
will be executed. Then if test2
is true, statementB
will be executed followed by statementC.
If test2 were false, then only
statementA
and
statementC
would be executed.
Another pseudocode example is as follows:
while(
test1 )
{
statementA;
if( test2 )
statementB;
}
In the above example, if test1 is true,
statementA
will be executed. Then if test2
is true, statementB
will be executed. Then the loop
condition test1 will be evaluated again. For as long as test1 is true,
statementA
followed by the
if
statement will continue to be executed.
You may now wish to revisit the statement
and control of execution concept map from Unit 3.
Back
to top
RITSEC - Global Campus
Copyright © 1999 RITSEC- Middlesex
University. All rights reserved.
webmaster@globalcampus.com.eg
|