Iteration: FOR, WHILE and REPEAT–UNTIL Loops – Grade 11 ICT Notes 1.7

© 2026 schoolict.net (Ruwan Mangala Suraweera)

1.7 Iteration: FOR, WHILE and REPEAT–UNTIL Loopsපුනරාවර්තනය: FOR, WHILE සහ REPEAT–UNTIL ලූප

G.C.E. O/L Grade 11 ICT · Lesson 1G.C.E. O/L ICT · 11 ශ්‍රේණිය · පාඩම 1

Prints all tabs in the language you are reading. Use “Save as PDF” in the print window to keep a copy.ඔබ කියවන භාෂාවෙන් සියලු tabs මුද්‍රණය වේ. පිටපතක් තියාගන්න print window එකේ “Save as PDF” තෝරන්න.
🎬Video coming soon in this language. Switch language to watch the other video.මේ භාෂාවෙන් වීඩියෝව ඉක්මනින් එනවා. අනෙක් වීඩියෝව බලන්න භාෂාව මාරු කරන්න.

In this videoමේ වීඩියෝවේ

  • Iteration repeats steps.පුනරාවර්තනය පියවර නැවත කරයි.
  • FOR: a fixed number of times.FOR: ස්ථාවර වාර ගණනක්.
  • WHILE: checks first; may run 0 times.WHILE: මුලින් පරීක්ෂා කරයි; 0 වරක් විය හැක.
  • REPEAT … UNTIL: checks last; runs at least once.REPEAT … UNTIL: අවසානයේ පරීක්ෂා; අවම වශයෙන් එක් වරක්.
  • Update the variable to avoid infinite loops.අනන්ත ලූප වැළැක්වීමට විචල්‍යය යාවත්කාලීන කරන්න.
FORWHILEREPEATCounterSentinelInfinite loopTotal

Notesසටහන්

Syllabus 10.7. A loop repeats statements. If we know how many times to repeat (e.g. 10 times), we use a FOR loop. If we don’t know (e.g. “until the user types −1”), we use a WHILE loop, which tests the condition at the beginning, or a REPEAT–UNTIL loop, which tests at the end. You will also learn to convert one loop into another.විෂය නිර්දේශය 10.7. ලූපයක් ප්‍රකාශ නැවත නැවත ක්‍රියාත්මක කරයි. කී වරක් කළ යුතුදැයි දන්නේ නම් (උදා 10 වරක්) FOR ලූපයක් භාවිත කරමු. නොදන්නේ නම් (උදා “පරිශීලකයා −1 ටයිප් කරන තුරු”) ආරම්භයේදී කොන්දේසිය පරීක්ෂා කරන WHILE ලූපයක් හෝ අවසානයේදී පරීක්ෂා කරන REPEAT–UNTIL ලූපයක් භාවිත කරමු. එක් ලූපයක් තවත් එකකට පරිවර්තනය කිරීමද ඉගෙන ගනිමු.

1. Known number of times: FOR1. දන්නා වාර ගණන: FOR

A FOR loop uses a counter that goes from a start value to an end value. The loop body runs once for each value. Example: the multiplication table of a number, 1 to 10.FOR ලූපයක් ආරම්භක අගයක සිට අවසාන අගයක් දක්වා යන ගණකයක් (counter) භාවිත කරයි. සෑම අගයකටම ලූපයේ ඇතුළත එක් වරක් ධාවනය වේ. උදාහරණය: සංඛ්‍යාවක ගුණන වගුව, 1 සිට 10 දක්වා.

📝 Pseudocodeව්‍යාජ කේතය (Pseudocode)

BEGIN
  INPUT N
  FOR i = 1 TO 10
    DISPLAY N, " x ", i, " = ", N * i
  ENDFOR
END
StartINPUT Ni = 1i <= 10?YesDISPLAY N x i = N * ii = i + 1NoStop
Flowchart – For loop (known count): multiplication tableගැලීම් සටහන – For loop (දන්නා වාර ගණන): ගුණන වගුව
💻 For loop (known count): multiplication tableFor loop (දන්නා වාර ගණන): ගුණන වගුව
program TimesTable;
var
  n, i: integer;
begin
  write('Enter a number: ');
  readln(n);
  for i := 1 to 10 do
    writeln(n, ' x ', i, ' = ', n * i);
end.
n = int(input("Enter a number: "))
for i in range(1, 11):
    print(n, "x", i, "=", n * i)

▶ Sample runනියැදි ධාවනය · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්‍රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)

Enter a number: 7
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70

Trace of a FOR loop – factorial of 5 (F = 1 × 2 × 3 × 4 × 5):FOR ලූපයක අනුරේඛනය – 5 හි සාධකීය (F = 1 × 2 × 3 × 4 × 5):

💻 Factorial with a FOR loopFOR loop මගින් ක්‍රමාරෝපිතය (factorial)
program Factorial;
var
  n, i, f: integer;
begin
  write('Enter N: ');
  readln(n);
  f := 1;
  for i := 1 to n do
    f := f * i;
  writeln('Factorial = ', f);
end.
n = int(input("Enter N: "))
f = 1
for i in range(1, n + 1):
    f = f * i
print("Factorial =", f)

▶ Sample runනියැදි ධාවනය · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්‍රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)

Enter N: 5
Factorial = 120
iiF = F * iF = F * i
1111
2222
3366
442424
55120120

2. Unknown count, test at the beginning: WHILE2. නොදන්නා වාර ගණන, ආරම්භයේ පරීක්ෂාව: WHILE

A WHILE loop checks the condition first. If it is True, the body runs and the condition is checked again. If it is False at the start, the body runs zero times. Example: enter marks until −1 is typed. −1 is a sentinel (a stop signal), not a mark.WHILE ලූපයක් කොන්දේසිය මුලින්ම පරීක්ෂා කරයි. සත්‍ය නම් ඇතුළත ධාවනය වී කොන්දේසිය නැවත පරීක්ෂා කරයි. ආරම්භයේදීම අසත්‍ය නම් ඇතුළත ශුන්‍ය වරක් ධාවනය වේ. උදාහරණය: −1 ටයිප් කරන තුරු ලකුණු ඇතුළත් කිරීම. −1 යනු ලකුණක් නොව sentinel (නැවතීමේ සංඥාවක්) අගයකි.

StartCondition?YesStatementsNoStop
General form of a WHILE loop (test at the beginning)WHILE ලූපයක සාමාන්‍ය ආකාරය (ආරම්භයේ පරීක්ෂාව)

📝 Pseudocodeව්‍යාජ කේතය (Pseudocode)

BEGIN
  Count = 0
  Total = 0
  INPUT Mark
  WHILE Mark <> -1 DO
    Count = Count + 1
    Total = Total + Mark
    INPUT Mark
  ENDWHILE
  IF Count > 0 THEN
    DISPLAY Count, Total, Total / Count
  ELSE
    DISPLAY "No marks entered"
  ENDIF
END
StartCount = 0, Total = 0INPUT MarkMark <> -1?YesCount = Count + 1Total = Total + MarkINPUT MarkNoCount > 0?DISPLAY Count, Total, Total / CountYesDISPLAY “No marks”NoStop
Flowchart – While loop (unknown count): marks until −1ගැලීම් සටහන – While loop (නොදන්නා වාර ගණන): −1 දක්වා ලකුණු
💻 While loop (unknown count): marks until −1While loop (නොදන්නා වාර ගණන): −1 දක්වා ලකුණු
program MarksUntilStop;
var
  mark, count, total: integer;
begin
  count := 0;
  total := 0;
  write('Enter mark (-1 to stop): ');
  readln(mark);
  while mark <> -1 do
  begin
    count := count + 1;
    total := total + mark;
    write('Enter mark (-1 to stop): ');
    readln(mark);
  end;
  if count > 0 then
  begin
    writeln('Count = ', count);
    writeln('Total = ', total);
    writeln('Average = ', total / count:0:2);
  end
  else
    writeln('No marks entered');
end.
count = 0
total = 0
mark = int(input("Enter mark (-1 to stop): "))
while mark != -1:
    count = count + 1
    total = total + mark
    mark = int(input("Enter mark (-1 to stop): "))
if count > 0:
    print("Count =", count)
    print("Total =", total)
    print(f"Average = {total / count:.2f}")
else:
    print("No marks entered")

▶ Sample runනියැදි ධාවනය 1 · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්‍රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)

Enter mark (-1 to stop): 70
Enter mark (-1 to stop): 85
Enter mark (-1 to stop): 64
Enter mark (-1 to stop): -1
Count = 3
Total = 219
Average = 73.00

▶ Sample runනියැදි ධාවනය 2 · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්‍රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)

Enter mark (-1 to stop): -1
No marks entered
MarkMarkCountCountTotalTotal
7070117070
858522155155
646433219219
-1-133219219

Count = 3, Total = 219, so Average = 219 ÷ 3 = 73.00. If the first input is −1, the loop body never runs and the program says “No marks entered”.Count = 3, Total = 219, එබැවින් සාමාන්‍යය = 219 ÷ 3 = 73.00. පළමු ආදානය −1 නම් ලූපයේ ඇතුළත කිසි විටෙක ධාවනය නොවී “No marks entered” කියයි.

3. Unknown count, test at the end: REPEAT–UNTIL3. නොදන්නා වාර ගණන, අවසානයේ පරීක්ෂාව: REPEAT–UNTIL

A REPEAT–UNTIL loop runs the body first and checks the condition at the end, so the body always runs at least once. It stops when the condition becomes True. Perfect for checking input: keep asking until a valid mark (0–100) is typed.REPEAT–UNTIL ලූපයක් ඇතුළත මුලින් ධාවනය කර අවසානයේදී කොන්දේසිය පරීක්ෂා කරයි, එබැවින් ඇතුළත සැමවිටම අවම වශයෙන් එක් වරක් ධාවනය වේ. කොන්දේසිය සත්‍ය වූ විට නවතී. ආදාන පරීක්ෂාවට ඉතා හොඳයි: වලංගු ලකුණක් (0–100) ටයිප් කරන තුරු දිගටම ඉල්ලීම.

StartStatementsCondition?NoYesStop
General form of a REPEAT–UNTIL loop (test at the end)REPEAT–UNTIL ලූපයක සාමාන්‍ය ආකාරය (අවසානයේ පරීක්ෂාව)

📝 Pseudocodeව්‍යාජ කේතය (Pseudocode)

BEGIN
  REPEAT
    INPUT Mark
    IF Mark < 0 OR Mark > 100 THEN
      DISPLAY "Invalid. Try again."
    ENDIF
  UNTIL Mark >= 0 AND Mark <= 100
  DISPLAY Mark
END
StartINPUT MarkMark < 0 OR Mark > 100?DISPLAY “Invalid”YesNoMark >= 0 AND Mark <= 100?NoYesDISPLAY MarkStop
Flowchart – Repeat–Until (checked at the end): accept a valid markගැලීම් සටහන – Repeat–Until (අවසානයේ පරීක්ෂාව): වලංගු ලකුණක් ලබාගැනීම
💻 Repeat–Until (checked at the end): accept a valid markRepeat–Until (අවසානයේ පරීක්ෂාව): වලංගු ලකුණක් ලබාගැනීම
program ValidMark;
var
  mark: integer;
begin
  repeat
    write('Enter mark (0-100): ');
    readln(mark);
    if (mark < 0) or (mark > 100) then
      writeln('Invalid. Try again.');
  until (mark >= 0) and (mark <= 100);
  writeln('Mark accepted: ', mark);
end.
while True:
    mark = int(input("Enter mark (0-100): "))
    if 0 <= mark <= 100:
        break
    print("Invalid. Try again.")
print("Mark accepted:", mark)

▶ Sample runනියැදි ධාවනය · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්‍රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)

Enter mark (0-100): 120
Invalid. Try again.
Enter mark (0-100): -5
Invalid. Try again.
Enter mark (0-100): 76
Mark accepted: 76
💡 Python has no REPEAT–UNTIL. We copy it with while True: … and break when the stop condition is reached.Python හි REPEAT–UNTIL නැත. while True: … සහ නැවතීමේ කොන්දේසිය ලැබුණු විට break භාවිතයෙන් එය අනුකරණය කරමු.

4. Comparing the three loops4. ලූප තුන සැසඳීම

FORFORWHILEWHILEREPEAT–UNTILREPEAT–UNTIL
Number of timesවාර ගණනKnownදනීUnknownනොදනීUnknownනොදනී
Condition testedකොන්දේසිය පරීක්ෂාවCounter checked at the startගණකය ආරම්භයේAt the beginningආරම්භයේAt the endඅවසානයේ
Minimum runsඅවම ධාවන000011
Stops whenනවතින්නේCounter passes the end valueගණකය අවසාන අගය ඉක්මවූ විටCondition is Falseකොන්දේසිය අසත්‍ය වූ විටCondition is Trueකොන්දේසිය සත්‍ය වූ විට
PascalPascalfor i := 1 to 10 dofor i := 1 to 10 dowhile … dowhile … dorepeat … until …;repeat … until …;
PythonPythonfor i in range(1, 11):for i in range(1, 11):while …:while …:while True: … breakwhile True: … break

5. Converting one loop into another5. එක් ලූපයක් තවත් එකකට පරිවර්තනය

The same task – display the even numbers 2, 4, 6, 8, 10 – written with each loop. To change a FOR into a WHILE: (1) set the counter before the loop, (2) write the condition, (3) increase the counter inside the loop. For REPEAT–UNTIL, reverse the condition (WHILE i <= 10 becomes UNTIL i > 10).එකම කාර්යය – 2, 4, 6, 8, 10 ඉරට්ටේ සංඛ්‍යා පෙන්වීම – එක් එක් ලූපයෙන් ලියා ඇත. FOR එකක් WHILE එකකට වෙනස් කිරීමට: (1) ලූපයට පෙර ගණකය සකසන්න, (2) කොන්දේසිය ලියන්න, (3) ලූපය තුළ ගණකය වැඩි කරන්න. REPEAT–UNTIL සඳහා කොන්දේසිය ප්‍රතිවිරුද්ධ කරන්න (WHILE i <= 10 වන්නේ UNTIL i > 10).

📝 Pseudocodeව්‍යාජ කේතය (Pseudocode)

BEGIN
  FOR i = 1 TO 5
    DISPLAY i * 2
  ENDFOR
END
💻 Even numbers 2–10 with FORFOR මගින් 2–10 ඉරට්ටේ සංඛ්‍යා
program EvenFor;
var
  i: integer;
begin
  for i := 1 to 5 do
    writeln(i * 2);
end.
for i in range(2, 11, 2):
    print(i)

▶ Sample runනියැදි ධාවනය · same output in Pascal and PythonPascal සහ Python දෙකෙහිම එකම ප්‍රතිදානය

2
4
6
8
10

📝 Pseudocodeව්‍යාජ කේතය (Pseudocode)

BEGIN
  i = 2
  WHILE i <= 10 DO
    DISPLAY i
    i = i + 2
  ENDWHILE
END
💻 Even numbers 2–10 with WHILEWHILE මගින් 2–10 ඉරට්ටේ සංඛ්‍යා
program EvenWhile;
var
  i: integer;
begin
  i := 2;
  while i <= 10 do
  begin
    writeln(i);
    i := i + 2;
  end;
end.
i = 2
while i <= 10:
    print(i)
    i = i + 2

▶ Sample runනියැදි ධාවනය · same output in Pascal and PythonPascal සහ Python දෙකෙහිම එකම ප්‍රතිදානය

2
4
6
8
10

📝 Pseudocodeව්‍යාජ කේතය (Pseudocode)

BEGIN
  i = 2
  REPEAT
    DISPLAY i
    i = i + 2
  UNTIL i > 10
END
Starti = 2DISPLAY ii = i + 2i > 10?NoYesStop
Flowchart – Even numbers 2–10 with REPEAT–UNTILගැලීම් සටහන – REPEAT–UNTIL මගින් 2–10 ඉරට්ටේ සංඛ්‍යා
💻 Even numbers 2–10 with REPEAT–UNTILREPEAT–UNTIL මගින් 2–10 ඉරට්ටේ සංඛ්‍යා
program EvenRepeat;
var
  i: integer;
begin
  i := 2;
  repeat
    writeln(i);
    i := i + 2;
  until i > 10;
end.
i = 2
while True:          # Python has no repeat-until
    print(i)
    i = i + 2
    if i > 10:
        break

▶ Sample runනියැදි ධාවනය · same output in Pascal and PythonPascal සහ Python දෙකෙහිම එකම ප්‍රතිදානය

2
4
6
8
10
💡 Danger – an infinite loop: if you forget i = i + 2 inside a WHILE loop, i stays 2 for ever and the loop never stops. Always check that something inside the loop moves it towards the end.අනතුර – අනන්ත ලූපය: WHILE ලූපයක් තුළ i = i + 2 අමතක වුවහොත් i සදහටම 2 ලෙස පවතින අතර ලූපය කිසි විටෙක නොනවතී. ලූපය තුළ යමක් එය අවසානය දෙසට ගෙන යන බව සැමවිටම පරීක්ෂා කරන්න.

Key Wordsප්‍රධාන පද

Loopලූපය
Statements that are repeated.නැවත නැවත ක්‍රියාත්මක වන ප්‍රකාශ.
FOR loopFOR ලූපය
A loop that runs a known number of times using a counter.ගණකයක් භාවිතයෙන් දන්නා වාර ගණනක් ධාවනය වන ලූපය.
WHILE loopWHILE ලූපය
A loop that tests its condition at the beginning.ආරම්භයේදී කොන්දේසිය පරීක්ෂා කරන ලූපය.
REPEAT–UNTIL loopREPEAT–UNTIL ලූපය
A loop that tests its condition at the end; runs at least once.අවසානයේදී කොන්දේසිය පරීක්ෂා කරන ලූපය; අවම වශයෙන් එක් වරක් ධාවනය වේ.
Counterගණකය
A variable that counts the loop runs, e.g. i.ලූප ධාවන ගණන් කරන විචල්‍යයක්, උදා i.
Pre-test loopපූර්ව-පරීක්ෂණ ලූපය
Condition checked before the body (WHILE, FOR).ඇතුළතට පෙර කොන්දේසිය පරීක්ෂාව (WHILE, FOR).
Post-test loopපශ්චාත්-පරීක්ෂණ ලූපය
Condition checked after the body (REPEAT–UNTIL).ඇතුළතට පසු කොන්දේසිය පරීක්ෂාව (REPEAT–UNTIL).
Sentinel valueSentinel අගය
A special value that means “stop”, e.g. −1.“නවතින්න” යන්න අදහස් කරන විශේෂ අගයක්, උදා −1.
Infinite loopඅනන්ත ලූපය
A loop that never stops.කිසි විටෙක නොනවතින ලූපයක්.
Validationවලංගුකරණය
Checking that input is sensible, e.g. a mark from 0 to 100.ආදානය සාධාරණදැයි පරීක්ෂාව, උදා 0 සිට 100 දක්වා ලකුණක්.
range()range()
Python function giving numbers for a FOR loop; range(1, 11) is 1 to 10.FOR ලූපයකට සංඛ්‍යා දෙන Python ශ්‍රිතය; range(1, 11) යනු 1 සිට 10.
breakbreak
Python word that leaves a loop at once.ලූපයකින් වහාම පිටවන Python වචනය.

Sample Q&Aආදර්ශ ප්‍රශ්න සහ පිළිතුරු

1When do we use a FOR loop?FOR ලූපයක් භාවිත කරන්නේ කවදාද?

Answerපිළිතුර: When we know how many times to repeat.කී වරක් පුනරාවර්තනය කළ යුතුදැයි දන්නා විට.

2What is the main difference between WHILE and REPEAT–UNTIL?WHILE සහ REPEAT–UNTIL අතර ප්‍රධාන වෙනස කුමක්ද?

Answerපිළිතුර: WHILE tests at the beginning (may run 0 times); REPEAT–UNTIL tests at the end (runs at least once).WHILE ආරම්භයේ පරීක්ෂා කරයි (0 වරක් ධාවනය විය හැක); REPEAT–UNTIL අවසානයේ පරීක්ෂා කරයි (අවම වශයෙන් එක් වරක්).

3What is a sentinel value?Sentinel අගයක් යනු කුමක්ද?

Answerපිළිතුර: A special value such as −1 that tells the loop to stop.ලූපයට නවතින ලෙස කියන −1 වැනි විශේෂ අගයක්.

4What is the factorial of 5?5 හි සාධකීය කුමක්ද?

Answerපිළිතුර: 120.120.

5How many times does for i := 1 to 10 run?for i := 1 to 10 කී වරක් ධාවනය වේද?

Answerපිළිතුර: 10 times.10 වරක්.

6What causes an infinite loop?අනන්ත ලූපයක් ඇති වන්නේ කුමක් නිසාද?

Answerපිළිතුර: The condition never changes, e.g. forgetting to increase the counter.කොන්දේසිය කිසි විටෙක වෙනස් නොවීම, උදා ගණකය වැඩි කිරීම අමතක වීම.

MCQබහුවරණ ප්‍රශ්න

Choose the correct answer for each question.සෑම ප්‍රශ්නයකටම නිවැරදි පිළිතුර තෝරන්න.

Scoreලකුණු: 0 / 15

1A loop for a known number of times is…දන්නා වාර ගණනක් සඳහා ලූපය…

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A

Known count → FOR.දන්නා ගණන → FOR.

2Which loop always runs at least once?සැමවිටම අවම වශයෙන් එක් වරක් ධාවනය වන ලූපය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D

Test at the end.අවසානයේ පරීක්ෂාව.

3Which loop tests the condition at the beginning?ආරම්භයේදී කොන්දේසිය පරීක්ෂා කරන ලූපය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B

Pre-test.පූර්ව-පරීක්ෂණ.

4REPEAT … UNTIL condition stops when the condition is…REPEAT … UNTIL කොන්දේසිය නවතින්නේ කොන්දේසිය…

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C

Until it becomes true.සත්‍ය වන තුරු.

5In Python, range(1, 11) gives…Python හි range(1, 11) දෙන්නේ…

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A

End not included.අවසානය ඇතුළත් නැත.

6The output of the factorial program for N = 5 is…N = 5 සඳහා සාධකීය වැඩසටහනේ ප්‍රතිදානය…

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B

1×2×3×4×5.1×2×3×4×5.

7Marks 70, 85, 64 then −1 are entered. The average shown is…ලකුණු 70, 85, 64 පසුව −1 ඇතුළත් කරයි. පෙන්වන සාමාන්‍යය…

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C

219 ÷ 3.219 ÷ 3.

8In the marks program, −1 is called a…ලකුණු වැඩසටහනේ −1 හඳුන්වන්නේ…

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D

Stop signal.නැවතීමේ සංඥාව.

9If the first input is −1, the WHILE loop body runs…පළමු ආදානය −1 නම් WHILE ලූපයේ ඇතුළත ධාවනය වන්නේ…

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A

Condition false at start.ආරම්භයේදීම අසත්‍යයි.

10Python has no REPEAT–UNTIL. We use…Python හි REPEAT–UNTIL නැත. අප භාවිත කරන්නේ…

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A

while True with break.break සමඟ while True.

11Changing “WHILE i <= 10” to REPEAT–UNTIL gives…“WHILE i <= 10” REPEAT–UNTIL ට වෙනස් කළ විට…

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C

Reverse the condition.කොන්දේසිය ප්‍රතිවිරුද්ධ කරන්න.

12Forgetting to increase the counter inside a WHILE loop causes…WHILE ලූපයක් තුළ ගණකය වැඩි කිරීම අමතක වීමෙන් ඇති වන්නේ…

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C

Never stops.නොනවතී.

13How many lines does the multiplication-table program print after the input?ගුණන වගු වැඩසටහන ආදානයෙන් පසු පේළි කීයක් මුද්‍රණය කරයි?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B

i = 1 to 10.i = 1 සිට 10.

14Asking again and again until a valid mark is typed is best done with…වලංගු ලකුණක් ටයිප් කරන තුරු නැවත නැවත ඉල්ලීමට වඩාත් සුදුසු…

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D

Must ask at least once.අවම වශයෙන් එක් වරක් ඉල්ලිය යුතුය.

15for i := 1 to 5 do write(i * 2) prints…for i := 1 to 5 do write(i * 2) මුද්‍රණය කරන්නේ…

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B

Doubles of 1–5.1–5 දෙගුණ.

MCQ answer keyMCQ පිළිතුරු

  1. A – Known count → FOR.දන්නා ගණන → FOR.
  2. D – Test at the end.අවසානයේ පරීක්ෂාව.
  3. B – Pre-test.පූර්ව-පරීක්ෂණ.
  4. C – Until it becomes true.සත්‍ය වන තුරු.
  5. A – End not included.අවසානය ඇතුළත් නැත.
  6. B – 1×2×3×4×5.1×2×3×4×5.
  7. C – 219 ÷ 3.219 ÷ 3.
  8. D – Stop signal.නැවතීමේ සංඥාව.
  9. A – Condition false at start.ආරම්භයේදීම අසත්‍යයි.
  10. A – while True with break.break සමඟ while True.
  11. C – Reverse the condition.කොන්දේසිය ප්‍රතිවිරුද්ධ කරන්න.
  12. C – Never stops.නොනවතී.
  13. B – i = 1 to 10.i = 1 සිට 10.
  14. D – Must ask at least once.අවම වශයෙන් එක් වරක් ඉල්ලිය යුතුය.
  15. B – Doubles of 1–5.1–5 දෙගුණ.

Structured Questionsව්‍යුහගත ප්‍රශ්න

1(i) Give one difference between a pre-test and a post-test loop. (2 marks)
(ii) Give one example of each in Pascal. (2 marks)
(i) පූර්ව-පරීක්ෂණ සහ පශ්චාත්-පරීක්ෂණ ලූප අතර එක් වෙනසක් දෙන්න. (ලකුණු 2)
(ii) Pascal හි එක් එකකට උදාහරණයක් දෙන්න. (ලකුණු 2)
(4 marksලකුණු 4)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
(i) A pre-test loop checks the condition before the body and may run 0 times; a post-test loop checks after and runs at least once. (ii) while … do (pre-test); repeat … until (post-test).(i) පූර්ව-පරීක්ෂණ ලූපය ඇතුළතට පෙර පරීක්ෂා කරන අතර 0 වරක් ධාවනය විය හැක; පශ්චාත්-පරීක්ෂණ ලූපය පසුව පරීක්ෂා කර අවම වශයෙන් එක් වරක් ධාවනය වේ. (ii) while … do (පූර්ව); repeat … until (පශ්චාත්).

2Write a program (Pascal or Python) to input a number and display its multiplication table from 1 to 10. (4 marks)සංඛ්‍යාවක් ආදානය කර එහි ගුණන වගුව 1 සිට 10 දක්වා පෙන්වන වැඩසටහනක් (Pascal හෝ Python) ලියන්න. (ලකුණු 4) (4 marksලකුණු 4)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
Input N (1); FOR i = 1 to 10 (1); calculate N × i (1); display in the form 7 x 1 = 7 (1).N ආදානය (1); FOR i = 1 සිට 10 (1); N × i ගණනය (1); 7 x 1 = 7 ආකාරයෙන් පෙන්වීම (1).
💻 For loop (known count): multiplication tableFor loop (දන්නා වාර ගණන): ගුණන වගුව
program TimesTable;
var
  n, i: integer;
begin
  write('Enter a number: ');
  readln(n);
  for i := 1 to 10 do
    writeln(n, ' x ', i, ' = ', n * i);
end.
n = int(input("Enter a number: "))
for i in range(1, 11):
    print(n, "x", i, "=", n * i)

▶ Sample runනියැදි ධාවනය · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්‍රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)

Enter a number: 7
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
7 x 10 = 70

3Write pseudocode that keeps reading marks until −1 is entered, then displays the count, total and average. (5 marks)−1 ඇතුළත් කරන තුරු ලකුණු කියවා, පසුව ගණන, එකතුව සහ සාමාන්‍යය පෙන්වන ව්‍යාජ කේතය ලියන්න. (ලකුණු 5) (5 marksලකුණු 5)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
Count = 0, Total = 0 (1); input Mark before the loop (1); WHILE Mark <> −1 add to Count and Total (1); input Mark inside the loop (1); display Count, Total, Total / Count (1).Count = 0, Total = 0 (1); ලූපයට පෙර Mark ආදානය (1); WHILE Mark <> −1 Count සහ Total ට එකතු කිරීම (1); ලූපය තුළ Mark ආදානය (1); Count, Total, Total / Count පෙන්වීම (1).

📝 Pseudocodeව්‍යාජ කේතය (Pseudocode)

BEGIN
  Count = 0
  Total = 0
  INPUT Mark
  WHILE Mark <> -1 DO
    Count = Count + 1
    Total = Total + Mark
    INPUT Mark
  ENDWHILE
  IF Count > 0 THEN
    DISPLAY Count, Total, Total / Count
  ELSE
    DISPLAY "No marks entered"
  ENDIF
END
MarkMarkCountCountTotalTotal
7070117070
858522155155
646433219219
-1-133219219

4Rewrite this FOR loop as a WHILE loop: FOR i = 1 TO 5 : DISPLAY i * 2 : ENDFOR. (3 marks)මෙම FOR ලූපය WHILE ලූපයක් ලෙස නැවත ලියන්න: FOR i = 1 TO 5 : DISPLAY i * 2 : ENDFOR. (ලකුණු 3) (3 marksලකුණු 3)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
i = 1 (1); WHILE i <= 5 DO DISPLAY i * 2 (1); i = i + 1; ENDWHILE (1). (Or the equivalent with i = 2 … i <= 10 … i = i + 2.)i = 1 (1); WHILE i <= 5 DO DISPLAY i * 2 (1); i = i + 1; ENDWHILE (1). (නැතහොත් i = 2 … i <= 10 … i = i + 2 සමාන ආකාරය.)

📝 Pseudocodeව්‍යාජ කේතය (Pseudocode)

BEGIN
  i = 2
  WHILE i <= 10 DO
    DISPLAY i
    i = i + 2
  ENDWHILE
END

5Complete a trace table for the factorial program with N = 5 and give the output. (3 marks)N = 5 සමඟ සාධකීය වැඩසටහන සඳහා අනුරේඛන වගුවක් සම්පූර්ණ කර ප්‍රතිදානය දෙන්න. (ලකුණු 3) (3 marksලකුණු 3)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
F = 1, 2, 6, 24, 120 for i = 1 to 5 (2); output Factorial = 120 (1).i = 1 සිට 5 සඳහා F = 1, 2, 6, 24, 120 (2); ප්‍රතිදානය Factorial = 120 (1).
iiF = F * iF = F * i
1111
2222
3366
442424
55120120

🎮 Game🎮 ක්‍රීඩා

Pick a game. Each one uses words from this lesson.ක්‍රීඩාවක් තෝරන්න. හැම එකක්ම මේ පාඩමේ වචන පාවිච්චි කරනවා.

Summary & Downloadsසාරාංශය සහ බාගත කිරීම්

Key pointsප්‍රධාන කරුණු

  • FOR: known number of times.FOR: දන්නා වාර ගණන.
  • WHILE: test at the beginning; may run 0 times.WHILE: ආරම්භයේ පරීක්ෂාව; 0 වරක් ධාවනය විය හැක.
  • REPEAT–UNTIL: test at the end; runs at least once.REPEAT–UNTIL: අවසානයේ පරීක්ෂාව; අවම වශයෙන් එක් වරක්.
  • REPEAT stops when the condition is True.REPEAT නවතින්නේ කොන්දේසිය සත්‍ය වූ විටය.
  • A sentinel (−1) tells the loop to stop.Sentinel (−1) ලූපයට නවතින ලෙස කියයි.
  • Python: for … in range(); while; while True + break.Python: for … in range(); while; while True + break.
  • Convert: set counter, test, increase inside.පරිවර්තනය: ගණකය සකසන්න, පරීක්ෂා කරන්න, තුළ වැඩි කරන්න.
  • Always move the loop towards its end – avoid infinite loops.ලූපය අවසානය දෙසට ගෙන යන්න – අනන්ත ලූප වළකින්න.

Downloadsබාගත කිරීම්

Full Lesson 1 PDFසම්පූර්ණ පාඩම 1 PDF: English · සිංහල

Next noteඊළඟ සටහන 1.8 →

© 2026 schoolict.net (Ruwan Mangala Suraweera). All rights reserved.සියලු හිමිකම් ඇවිරිණි.