5.1.1 Write down the line number of any line of code from the provided code segment above that implements the following:
(a) Initialisation
(b) Looping
5.1.2 What will be the value of iCounter after the above code has been executed?
NOTE: Assume that all the variables are declared correctly and there are no errors in the code - NSC Information Technology - Question 5 - 2023 - Paper 2
Question 5
5.1.1 Write down the line number of any line of code from the provided code segment above that implements the following:
(a) Initialisation
(b) Looping
5.1.2 What ... show full transcript
Worked Solution & Example Answer:5.1.1 Write down the line number of any line of code from the provided code segment above that implements the following:
(a) Initialisation
(b) Looping
5.1.2 What will be the value of iCounter after the above code has been executed?
NOTE: Assume that all the variables are declared correctly and there are no errors in the code - NSC Information Technology - Question 5 - 2023 - Paper 2
Step 1
Write down the line number of any line of code that implements Initialisation
96%
114 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Line 1 (iCounter := 0)
Step 2
Write down the line number of any line of code that implements Looping
99%
104 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Line 4 (sLine := '')
Step 3
What will be the value of iCounter after the above code has been executed?
96%
101 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The value of iCounter after execution will be 15, as it is incremented 15 times (3 for the outer loop and 5 for the inner loop).
Step 4
Provide the output of the program after the code above has been executed.
98%
120 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
The output of the program will be a single line consisting of 15 asterisks: '*****'.
Step 5
Rewrite the second loop (for iCol := 1 to 5 do) as a conditional loop.
97%
117 rated
Only available for registered users.
Sign up now to view full answer, or log in if you already have an account!
Answer
Using a conditional loop, it could be expressed as:
iCol := 1;
while iCol <= 5 do
begin
inc(iCol);
end;
This loop will continue to execute as long as iCol is less than or equal to 5.