9.1 AS Loops
9.1 AS Loops
9.1 AS Loops
Inqilab Patel is an O & A Level Computer Teacher. Currently he is teaching A & O Level Computer Science
at The City School PAF Chapters, Hira Foundation School and Intellect. He has taught in many other
schools including Yaqeen Model School, Karachi Cadet School, KN Academy, Hexis A Level, Verge and
Nakhlah Boys Campus Society. Cambridge has selected him as a Member of Cambridge Editorial
Review Board. He is also associated with Aga Khan University Examination Board in the capacity of
Chief Examiner, Item Writer, E-Marker, Karachi Board of Secondary Education the capacity of
Deputy Head Examiner and Sindh Board of Technical Education.
His entire career path revolves around computer science; either he was a student or a teacher.
He got a chance to polish his skills of teaching and studying more about computers at various
levels which has given him great confidence in presenting himself for any senior level position of
transferring his knowledge to the youth.
He has not stopped; he is continuing with his education at the higher levels. It is his second
semester of MPhil computer studies from a well-known university of Pakistan; The Institute of
Business & Technology.
Inqilab Patel knows a lot of methods of teaching computers and has developed tutorial notes,
worksheets and assignments for my students. He also maintains a website
(www.inqilabpatel.com) which is specifically designed for the support of those who want to excel
in GCSE computer science. He also regularly contributes material to CIE teacher support website,
for which he receives appreciation from different people across the world.
He has also received various training in innovative and special methods of teaching this subject.
LOOPING STATEMENTS:
1. FOR TO NEXT: Count Controlled loop
2. REPEAT UNTIL : Post Condition loop
3. WHILE DO ENDWHILE: Pre-Condition Loop
Count-controlled (FOR) loops
a count-controlled loop that is executed a set number of time.
It is written as follows:
<statement(s)>
NEXT <identifier>
The identifier must be a variable of data type INTEGER, and the values should be expressions that
evaluate to integers.
The variable is assigned each of the integer values from value1 to value2 inclusive, running the
statements inside the FOR loop after each assignment. If value1 = value2 the statements will be
executed once, and if value1 > value2 the statements will not be executed.
It is good practice to repeat the identifier after NEXT, particularly with nested FOR loops. An
increment can be specified as follows:
<statement(s)>
NEXT <identifier>
The increment must be an expression that evaluates to an integer. In this case the identifier will be as
signed the values from value1 in successive increments of increment until it reaches value2. If it goes
past value2, the loop terminates. The increment can be negative.
Example – nested FOR loops
NEXT Column
OUTPUT "Total for Row ", Row, " is ", RowTotal
NEXT Row
OUTPUT "The grand total is ", Total
Problem: Input daily wages and number of day worked and output monthly pay for 100 employees.
Problem: Input marks of 30 students in a class output result of each student. Passing marks is 40
problem: To input and add a series of positive numbers in total. Continue this process for input of
positive numbers
WHILE
Problem: Input a series of numbers, calculate their total, stop input if total is more than 100
REPEAT UNTIL Loop
Differences between
Pre-Condition Post Condition
(a) Find the error in the pseudo code and suggest a correction.
Error 1 ................................................................................................................................................
Correction ...........................................................................................................................................
......................................................................................................................................................[2]
(b) Rewrite the correct algorithm using a more suitable loop structure.
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
.............................. [3]
Q 9.6) Write an algorithm, using pseudo code and a FOR TO NEXT loop structure, to input 1000 numbers
into an array.
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
................................................................................................................................................................................
...................................................[2]
Summer 2015 P22
Complete the table by putting a tick ( ) in the appropriate column for each item.
..................................................................................................................
......................... ..................................................................................................................
..................................................................................................................
..................................................................................................................
..................................................................................................................
......................... ..................................................................................................................
..................................................................................................................
..................................................................................................................
(ii) Simple algorithms usually consist of input, process and output.
[4]
Pseudocode statement Input Process Output
Temp SensorValue * Factor
WRITEFILE "LogFile.txt", TextLine
WRITEFILE "LogFile.txt", MyName&MyIDNumber
READFILE "AddressBook.txt", NextLine
(c) White-box and black-box are two types of testing. In white-box testing, data are chosen to
test every possible path through the program.
Explain how data are chosen in black-box testing.
...................................................................................................................................................
............................................................................................................................................. [2]
Write the equivalent pseudocode using a pre-condition loop, for this part of the amended
flowchart.
E 15 .................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
.................................................................
Complete the table by putting a tick ( ) in the appropriate column for each item. [6]
(ii) State the purpose of each statement in the table in part (a)(i).
Do not use mathematical symbols in your descriptions. [6]
Item Purpose of statement
1 ...............................................................................................................................................
...............................................................................................................................................
2 ...............................................................................................................................................
...............................................................................................................................................
3 ...............................................................................................................................................
...............................................................................................................................................
4 ...............................................................................................................................................
...............................................................................................................................................
5 ...............................................................................................................................................
...............................................................................................................................................
6 ...............................................................................................................................................
...............................................................................................................................................
(ii) Identify the type of programming statement that assigns a data type to a variable.
..................................................................................................................................... [1]
Process
(ii) Write a single statement in program code that contains two of the stages. Do not repeat any of
the statements from part (c)(i).
..................................................................................................................................... [1]
(d) A software developer is writing a program and includes several features to make it easier to
read and understand. One of these features is the use of indentation.
State three other features.
Feature 1 ..................................................................................................................................
Feature 2 ..................................................................................................................................
Feature 3 .................................................................................................................................. [3]
(e) A trace table is often used during program testing.
Identify the type of testing that includes the use of a trace table.
............................................................................................................................................. [1]
2 (a) (i) Two types of loop that may be found in an algorithm are the ‘pre-condition’ and ‘post
condition’ loop.
Identify one other type of loop. Explain when it should be used.
Type ..................................................................................................................................
Explanation .......................................................................................................................
...........................................................................................................................................
.................................................................................................................................... [2]