0% found this document useful (0 votes)
9 views12 pages

Understanding Nested Statements in Programming

The document explains nested statements in programming, focusing on selection and iteration statements that can be combined to reduce code complexity. It provides examples of how to use nested loops and conditional statements to count numbers based on specific criteria. Additionally, it outlines tasks for developing pseudocode to calculate and output various statistics related to student marks.

Uploaded by

19465dxbp
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views12 pages

Understanding Nested Statements in Programming

The document explains nested statements in programming, focusing on selection and iteration statements that can be combined to reduce code complexity. It provides examples of how to use nested loops and conditional statements to count numbers based on specific criteria. Additionally, it outlines tasks for developing pseudocode to calculate and output various statistics related to student marks.

Uploaded by

19465dxbp
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Nested

statements

LO: Understand and use nested statements


Keywords: Selection, Iteration
CCL: Maths
Starter

 Identify the innermost loop, inner loop and outer loop,


FOR i 1 to 10
FOR j 1 to 5
FOR k 1 to 15
statements
NEXT k
NEXT j
NEXT i
Use of nested statements

 A nested statement is one or more selection and/or


iteration statements inside another selection/iteration
statement.
 Selection and iteration statements can be nested one
inside the other.
 This powerful method reduces the amount of code
that needs to be written and makes it simpler for a
programmer to test their programs.
Example 1

 Count how many numbers entered are more than 10,


and how many are equal to 10:
Sol
 MoreThanl0 <---- 0
 EqualTol0 <---- 0
 FOR Count <---- 0 TO 99
 OUTPUT ( "Enter a number" )
 INPUT Number
 IF Number > 10
 THEN
 MoreThanl0 <---- MoreThanl0 + 1
 ELSE
 IF Number = 10
 THEN
 EqualTol0 <---- EqualTol0 + 1
 ENDIF
 ENDIF
 NEXT Count
 This code has an IF statement nested inside a count-controlled loop.
Task
Develop the pseudocode that
 calculate and output highest, lowest, and average marks
awarded for a class of twenty students
 calculate and output largest, highest, lowest, and average
marks awarded for each student
 calculate and output largest, highest, lowest, and average
marks for each of the six subjects studied by the student;
each subject has five tests.
 assume that all marks input are whole numbers between 0
and 100.
Solution
HW

 When the single student program is working,


extend your program to complete the task to
calculate and output the largest, highest, lowest,
and average marks for the whole class of 20
students.
Reference

 [Link]
 [Link]
 [Link]
s/
 [Link]

You might also like