Nested Control Structures – Grade 11 ICT Notes 1.8

© 2026 schoolict.net (Ruwan Mangala Suraweera)

1.8 Nested Control Structuresකැදැලි පාලන ව්‍යුහ

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මේ වීඩියෝවේ

  • Nesting: a structure inside another.කැදැලි: ව්‍යුහයක් තුළ තවත් එකක්.
  • Nested IF: largest of three.කැදැලි IF: තුනෙන් විශාලතම.
  • Inner loop runs fully for each outer run.පිටත සෑම ධාවනයකටම ඇතුළු ලූපය සම්පූර්ණයෙන් ධාවනය වේ.
  • IF inside a loop: count passes.ලූපය තුළ IF: සමත් ගණන් කිරීම.
  • Indent each level; close inner first.සෑම මට්ටමක්ම ඉන්ඩෙන්ට් කරන්න; ඇතුළත මුලින් වසන්න.
NestingNested IFNested loopInner loopOuter loopIndentationLevel

Notesසටහන්

Syllabus 10.8. A structure placed inside another structure is nested – like a small box inside a bigger box. We can put a selection inside a selection, a loop inside a loop, a selection inside a loop, or a loop inside a selection. Real programs use nesting all the time.විෂය නිර්දේශය 10.8. වෙනත් ව්‍යුහයක් තුළ තැබූ ව්‍යුහයක් කැදැලි (nested) වේ – විශාල පෙට්ටියක් තුළ ඇති කුඩා පෙට්ටියක් මෙන්. වරණයක් තුළ වරණයක්, ලූපයක් තුළ ලූපයක්, ලූපයක් තුළ වරණයක් හෝ වරණයක් තුළ ලූපයක් තැබිය හැක. සැබෑ වැඩසටහන් නිතරම කැදැලි භාවිත කරයි.

1. Selection inside selection1. වරණයක් තුළ වරණයක්

To find the largest of three numbers A, B and C: first ask “Is A > B?”. Then, inside each answer, ask a second question with C. The inner IF runs only when the outer IF reaches it.A, B සහ C සංඛ්‍යා තුනෙන් විශාලතම එක සොයා ගැනීමට: මුලින් “A > B ද?” යැයි අසන්න. පසුව එක් එක් පිළිතුර තුළ C සමඟ දෙවන ප්‍රශ්නයක් අසන්න. ඇතුළු IF එක ධාවනය වන්නේ පිටත IF එක එයට ළඟා වූ විට පමණි.

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

BEGIN
  INPUT A, B, C
  IF A > B THEN
    IF A > C THEN
      Largest = A
    ELSE
      Largest = C
    ENDIF
  ELSE
    IF B > C THEN
      Largest = B
    ELSE
      Largest = C
    ENDIF
  ENDIF
  DISPLAY Largest
END
StartINPUT A, B, CA > B?A > C?Largest = AYesLargest = CNoYesB > C?Largest = BYesLargest = CNoNoDISPLAY LargestStop
Flowchart – Selection inside selection: largest of threeගැලීම් සටහන – වරණය තුළ වරණය: තුනෙන් විශාලතම
💻 Selection inside selection: largest of threeවරණය තුළ වරණය: තුනෙන් විශාලතම
program Largest3;
var
  a, b, c, largest: integer;
begin
  write('Enter A: ');
  readln(a);
  write('Enter B: ');
  readln(b);
  write('Enter C: ');
  readln(c);
  if a > b then
  begin
    if a > c then
      largest := a
    else
      largest := c;
  end
  else
  begin
    if b > c then
      largest := b
    else
      largest := c;
  end;
  writeln('Largest = ', largest);
end.
a = int(input("Enter A: "))
b = int(input("Enter B: "))
c = int(input("Enter C: "))
if a > b:
    if a > c:
        largest = a
    else:
        largest = c
else:
    if b > c:
        largest = b
    else:
        largest = c
print("Largest =", largest)

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

Enter A: 12
Enter B: 45
Enter C: 30
Largest = 45

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

Enter A: 50
Enter B: 20
Enter C: 35
Largest = 50

2. Iteration inside iteration2. ලූපයක් තුළ ලූපයක්

An inner loop runs completely for every single run of the outer loop. In the star triangle, the outer loop chooses the row; the inner loop prints that many stars.පිටත ලූපයේ සෑම ධාවනයකටම ඇතුළු ලූපය සම්පූර්ණයෙන් ධාවනය වේ. තරු ත්‍රිකෝණයේ පිටත ලූපය පේළිය තෝරයි; ඇතුළු ලූපය එම ගණනට තරු මුද්‍රණය කරයි.

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

BEGIN
  FOR Row = 1 TO 4
    FOR Col = 1 TO Row
      DISPLAY "*" (same line)
    ENDFOR
    Move to a new line
  ENDFOR
END
StartRow = 1Row <= 4?YesCol = 1Col <= Row?YesDISPLAY “*”Col = Col + 1NoNew lineRow = Row + 1NoStop
Flowchart – Iteration inside iteration: star triangleගැලීම් සටහන – පුනරාවර්තනය තුළ පුනරාවර්තනය: තරු ත්‍රිකෝණය
💻 Iteration inside iteration: star triangleපුනරාවර්තනය තුළ පුනරාවර්තනය: තරු ත්‍රිකෝණය
program Stars;
var
  row, col: integer;
begin
  for row := 1 to 4 do
  begin
    for col := 1 to row do
      write('*');
    writeln;
  end;
end.
for row in range(1, 5):
    for col in range(1, row + 1):
        print("*", end="")
    print()

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

*
**
***
****
RowRowInner loop runs (times)ඇතුළු ලූපය ධාවනය (වාර)Printedමුද්‍රණය වූ දේ
1111**
2222****
3333******
4444********
💡 Total stars = 1 + 2 + 3 + 4 = 10. If the outer loop runs 4 times and the inner loop always ran 3 times, the inner body would run 4 × 3 = 12 times.මුළු තරු = 1 + 2 + 3 + 4 = 10. පිටත ලූපය 4 වරක් සහ ඇතුළු ලූපය සැමවිටම 3 වරක් ධාවනය වූයේ නම්, ඇතුළත 4 × 3 = 12 වරක් ධාවනය වේ.

3. Selection inside iteration3. ලූපයක් තුළ වරණයක්

A loop reads 5 marks. Inside the loop, an IF decides whether each mark is a pass (≥ 35) or a fail, and counts them.ලූපයක් ලකුණු 5ක් කියවයි. ලූපය තුළ, IF එකක් එක් එක් ලකුණ සමත්ද (≥ 35) අසමත්ද යන්න තීරණය කර ඒවා ගණන් කරයි.

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

BEGIN
  Passes = 0
  Fails = 0
  FOR i = 1 TO 5
    INPUT Mark
    IF Mark >= 35 THEN
      Passes = Passes + 1
    ELSE
      Fails = Fails + 1
    ENDIF
  ENDFOR
  DISPLAY Passes, Fails
END
StartPasses = 0, Fails = 0, i = 1i <= 5?YesINPUT MarkMark >= 35?Passes = Passes + 1YesFails = Fails + 1Noi = i + 1NoDISPLAY Passes, FailsStop
Flowchart – Selection inside iteration: count passes and failsගැලීම් සටහන – පුනරාවර්තනය තුළ වරණය: සමත් සහ අසමත් ගණන් කිරීම
💻 Selection inside iteration: count passes and failsපුනරාවර්තනය තුළ වරණය: සමත් සහ අසමත් ගණන් කිරීම
program PassCount;
var
  i, mark, passes, fails: integer;
begin
  passes := 0;
  fails := 0;
  for i := 1 to 5 do
  begin
    write('Enter mark ', i, ': ');
    readln(mark);
    if mark >= 35 then
      passes := passes + 1
    else
      fails := fails + 1;
  end;
  writeln('Pass = ', passes);
  writeln('Fail = ', fails);
end.
passes = 0
fails = 0
for i in range(1, 6):
    mark = int(input(f"Enter mark {i}: "))
    if mark >= 35:
        passes = passes + 1
    else:
        fails = fails + 1
print("Pass =", passes)
print("Fail =", fails)

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

Enter mark 1: 45
Enter mark 2: 30
Enter mark 3: 78
Enter mark 4: 22
Enter mark 5: 60
Pass = 3
Fail = 2

4. Iteration inside selection4. වරණයක් තුළ ලූපයක්

First check that the input is positive. Only if it is, run a loop that displays the squares 1², 2², …මුලින් ආදානය ධනදැයි පරීක්ෂා කරන්න. එසේ නම් පමණක්, 1², 2², … වර්ග පෙන්වන ලූපයක් ධාවනය කරන්න.

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

BEGIN
  INPUT N
  IF N > 0 THEN
    FOR i = 1 TO N
      DISPLAY i * i
    ENDFOR
  ELSE
    DISPLAY "Please enter a positive number"
  ENDIF
END
StartINPUT NN > 0?i = 1i <= N?YesDISPLAY i * ii = i + 1NoYesDISPLAY “Positive only”NoStop
Flowchart – Iteration inside selection: squares only for a positive numberගැලීම් සටහන – වරණය තුළ පුනරාවර්තනය: ධන සංඛ්‍යාවකට පමණක් වර්ග
💻 Iteration inside selection: squares only for a positive numberවරණය තුළ පුනරාවර්තනය: ධන සංඛ්‍යාවකට පමණක් වර්ග
program Squares;
var
  n, i: integer;
begin
  write('How many squares? ');
  readln(n);
  if n > 0 then
  begin
    for i := 1 to n do
      writeln('Square of ', i, ' = ', i * i);
  end
  else
    writeln('Please enter a positive number');
end.
n = int(input("How many squares? "))
if n > 0:
    for i in range(1, n + 1):
        print("Square of", i, "=", i * i)
else:
    print("Please enter a positive number")

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

How many squares? 4
Square of 1 = 1
Square of 2 = 4
Square of 3 = 9
Square of 4 = 16

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

How many squares? -2
Please enter a positive number

5. Tips for nested code5. කැදැලි කේත සඳහා උපදෙස්

  • Indent each inner level a little more, so you can see which statement belongs where.සෑම ඇතුළු මට්ටමක්ම තව ටිකක් ඉන්ඩෙන්ට් කරන්න, එවිට කුමන ප්‍රකාශය කොතැනට අයත්දැයි පෙනේ.
  • Close the inner structure before the outer one (ENDIF before ENDFOR).පිටත එකට පෙර ඇතුළු ව්‍යුහය වසන්න (ENDFOR ට පෙර ENDIF).
  • In Pascal, use begin … end when a part has more than one statement.Pascal හි කොටසක ප්‍රකාශ එකකට වඩා ඇති විට begin … end භාවිත කරන්න.
  • Use different counter names for nested loops (Row and Col, i and j).කැදැලි ලූප සඳහා වෙනස් ගණක නම් භාවිත කරන්න (Row සහ Col, i සහ j).

Key Wordsප්‍රධාන පද

Nestingකැදැලි කිරීම
Placing one control structure inside another.එක් පාලන ව්‍යුහයක් තවත් එකක් තුළ තැබීම.
Nested IFකැදැලි IF
An IF inside another IF.වෙනත් IF එකක් තුළ ඇති IF එකක්.
Nested loopකැදැලි ලූපය
A loop inside another loop.වෙනත් ලූපයක් තුළ ඇති ලූපයක්.
Outer loopපිටත ලූපය
The loop that contains another loop.වෙනත් ලූපයක් අඩංගු ලූපය.
Inner loopඇතුළු ලූපය
The loop inside; it runs fully for each outer run.ඇතුළත ලූපය; පිටතේ සෑම ධාවනයකටම සම්පූර්ණයෙන් ධාවනය වේ.
Indentationඉන්ඩෙන්ටේෂන්
Spaces that show which level a statement belongs to.ප්‍රකාශයක් අයත් මට්ටම පෙන්වන හිස්තැන්.
begin … endbegin … end
Pascal words that group several statements into one block.ප්‍රකාශ කිහිපයක් එක් කාණ්ඩයකට එක් කරන Pascal වචන.
Largestවිශාලතම
The biggest value in a group.කණ්ඩායමක ඇති විශාලතම අගය.
Pass countසමත් ගණන
A counter that adds 1 for every pass.සෑම සමත් වීමකටම 1 ක් එකතු කරන ගණකය.
Squareවර්ගය
A number multiplied by itself, e.g. 4 × 4 = 16.සංඛ්‍යාවක් එයින්ම ගුණ කිරීම, උදා 4 × 4 = 16.
Positive numberධන සංඛ්‍යාව
A number greater than 0.0 ට වැඩි සංඛ්‍යාවක්.
Levelමට්ටම
How deep a structure is inside others.ව්‍යුහයක් අන් ඒවා තුළ කෙතරම් ගැඹුරින් ඇත්ද යන්න.

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

1What is a nested structure?කැදැලි ව්‍යුහයක් යනු කුමක්ද?

Answerපිළිතුර: A control structure placed inside another one.වෙනත් පාලන ව්‍යුහයක් තුළ තැබූ පාලන ව්‍යුහයකි.

2For A = 12, B = 45, C = 30, what does the largest-of-three program display?A = 12, B = 45, C = 30 සඳහා විශාලතම-තුනෙන් වැඩසටහන පෙන්වන්නේ කුමක්ද?

Answerපිළිතුර: Largest = 45.Largest = 45.

3If the outer loop runs 3 times and the inner loop runs 4 times each time, how many times does the inner body run?පිටත ලූපය 3 වරක් සහ ඇතුළු ලූපය සෑම විටම 4 වරක් ධාවනය වේ නම් ඇතුළත කී වරක් ධාවනය වේද?

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

4Marks 45, 30, 78, 22, 60 – how many passes and fails?ලකුණු 45, 30, 78, 22, 60 – සමත් සහ අසමත් කීයද?

Answerපිළිතුර: Pass = 3, Fail = 2.සමත් = 3, අසමත් = 2.

5What does the squares program show for −2?squares වැඩසටහන −2 සඳහා පෙන්වන්නේ කුමක්ද?

Answerපිළිතුර: Please enter a positive number.Please enter a positive number.

6Why do we indent nested code?කැදැලි කේත ඉන්ඩෙන්ට් කරන්නේ ඇයි?

Answerපිළිතුර: To see clearly which statements belong to which structure.කුමන ප්‍රකාශ කුමන ව්‍යුහයට අයත්දැයි පැහැදිලිව දැකීමට.

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

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

Scoreලකුණු: 0 / 15

1A loop placed inside another loop is a…වෙනත් ලූපයක් තුළ තැබූ ලූපයක්…

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

Nested.කැදැලි.

2For A = 50, B = 20, C = 35, the largest is…A = 50, B = 20, C = 35 සඳහා විශාලතම…

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

A is biggest.A විශාලතමයි.

3In the largest-of-three flowchart, the first question is…විශාලතම-තුනෙන් ගැලීම් සටහනේ පළමු ප්‍රශ්නය…

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

Outer IF.පිටත IF.

4Outer loop runs 4 times, inner loop 3 times each. Inner body runs…පිටත ලූපය 4 වරක්, ඇතුළු ලූපය සෑම විටම 3 වරක්. ඇතුළත ධාවනය වන්නේ…

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

4 × 3.4 × 3.

5The last line of the star triangle (Row = 4) is…තරු ත්‍රිකෝණයේ අවසාන පේළිය (Row = 4)…

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

4 stars.තරු 4.

6Total stars in the 4-row triangle…පේළි 4ක ත්‍රිකෝණයේ මුළු තරු…

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

1+2+3+4.1+2+3+4.

7In the star program, the inner loop runs while…තරු වැඩසටහනේ ඇතුළු ලූපය ධාවනය වන්නේ…

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

Inner condition.ඇතුළු කොන්දේසිය.

8Marks 45, 30, 78, 22, 60 give Pass = …ලකුණු 45, 30, 78, 22, 60 අනුව Pass = …

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

45, 78, 60.45, 78, 60.

9Counting passes inside a loop is an example of…ලූපයක් තුළ සමත් ගණන් කිරීම … සඳහා උදාහරණයකි

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

IF inside FOR.FOR තුළ IF.

10The squares program checks the number first, then loops. This is…squares වැඩසටහන මුලින් සංඛ්‍යාව පරීක්ෂා කර පසුව ලූප කරයි. මෙය…

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

FOR inside IF.IF තුළ FOR.

11For input 4, the last line of the squares program is…ආදානය 4 සඳහා squares වැඩසටහනේ අවසාන පේළිය…

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

4 × 4.4 × 4.

12Which should be closed first?මුලින්ම වැසිය යුත්තේ කුමක්ද?

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

Inner first.ඇතුළත මුලින්.

13In Pascal, several statements inside an IF must be grouped with…Pascal හි IF එකක් තුළ ප්‍රකාශ කිහිපයක් කාණ්ඩ කළ යුත්තේ…

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

begin … end.begin … end.

14Good names for two nested loop counters are…කැදැලි ලූප ගණක දෙකකට හොඳ නම්…

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

Different names.වෙනස් නම්.

15Nesting means…කැදැලි කිරීම යනු…

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

Definition.අර්ථය.

MCQ answer keyMCQ පිළිතුරු

  1. C – Nested.කැදැලි.
  2. A – A is biggest.A විශාලතමයි.
  3. D – Outer IF.පිටත IF.
  4. B – 4 × 3.4 × 3.
  5. B – 4 stars.තරු 4.
  6. A – 1+2+3+4.1+2+3+4.
  7. C – Inner condition.ඇතුළු කොන්දේසිය.
  8. D – 45, 78, 60.45, 78, 60.
  9. A – IF inside FOR.FOR තුළ IF.
  10. D – FOR inside IF.IF තුළ FOR.
  11. B – 4 × 4.4 × 4.
  12. C – Inner first.ඇතුළත මුලින්.
  13. B – begin … end.begin … end.
  14. C – Different names.වෙනස් නම්.
  15. A – Definition.අර්ථය.

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

1Draw a flowchart to input three numbers A, B and C and display the largest, using nested IFs. (5 marks)කැදැලි IF භාවිතයෙන් A, B සහ C සංඛ්‍යා තුනක් ආදානය කර විශාලතම එක පෙන්වන ගැලීම් සටහනක් අඳින්න. (ලකුණු 5) (5 marksලකුණු 5)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
Start/input (1); A > B? (1); Yes → A > C? (1); No → B > C? (1); assign Largest and display, Stop (1).Start/ආදානය (1); A > B? (1); ඔව් → A > C? (1); නැත → B > C? (1); Largest පැවරීම සහ පෙන්වීම, Stop (1).
StartINPUT A, B, CA > B?A > C?Largest = AYesLargest = CNoYesB > C?Largest = BYesLargest = CNoNoDISPLAY LargestStop
Flowchart – Selection inside selection: largest of threeගැලීම් සටහන – වරණය තුළ වරණය: තුනෙන් විශාලතම

2Write a program (Pascal or Python) that uses nested loops to print the triangle *, , *, ****. (4 marks)*, , *, **** ත්‍රිකෝණය මුද්‍රණය කිරීමට කැදැලි ලූප භාවිත කරන වැඩසටහනක් (Pascal හෝ Python) ලියන්න. (ලකුණු 4) (4 marksලකුණු 4)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
Outer loop Row 1 to 4 (1); inner loop Col 1 to Row (1); print * without new line (1); new line after the inner loop (1).පිටත ලූපය Row 1 සිට 4 (1); ඇතුළු ලූපය Col 1 සිට Row (1); නව පේළියක් නැතිව * මුද්‍රණය (1); ඇතුළු ලූපයට පසු නව පේළිය (1).
💻 Iteration inside iteration: star triangleපුනරාවර්තනය තුළ පුනරාවර්තනය: තරු ත්‍රිකෝණය
program Stars;
var
  row, col: integer;
begin
  for row := 1 to 4 do
  begin
    for col := 1 to row do
      write('*');
    writeln;
  end;
end.
for row in range(1, 5):
    for col in range(1, row + 1):
        print("*", end="")
    print()

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

*
**
***
****

3Write pseudocode to read 5 marks and count how many are passes (≥ 35) and how many are fails. (5 marks)ලකුණු 5ක් කියවා සමත් (≥ 35) කීයද අසමත් කීයද යන්න ගණන් කරන ව්‍යාජ කේතය ලියන්න. (ලකුණු 5) (5 marksලකුණු 5)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
PassCount = 0, FailCount = 0 (1); FOR k = 1 TO 5 (1); INPUT Mark (1); IF Mark >= 35 add 1 to PassCount ELSE to FailCount (1); display both (1).PassCount = 0, FailCount = 0 (1); FOR k = 1 TO 5 (1); INPUT Mark (1); IF Mark >= 35 PassCount ට 1 ELSE FailCount ට 1 (1); දෙකම පෙන්වීම (1).

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

BEGIN
  Passes = 0
  Fails = 0
  FOR i = 1 TO 5
    INPUT Mark
    IF Mark >= 35 THEN
      Passes = Passes + 1
    ELSE
      Fails = Fails + 1
    ENDIF
  ENDFOR
  DISPLAY Passes, Fails
END

4Name the four kinds of nesting and give an example of each. (4 marks)කැදැලි කිරීමේ වර්ග හතර නම් කර එක් එකකට උදාහරණයක් දෙන්න. (ලකුණු 4) (4 marksලකුණු 4)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
Selection in selection – largest of three; iteration in iteration – star triangle; selection in iteration – count passes; iteration in selection – squares only for a positive number (1 each).වරණය තුළ වරණය – තුනෙන් විශාලතම; ලූපය තුළ ලූපය – තරු ත්‍රිකෝණය; ලූපය තුළ වරණය – සමත් ගණන් කිරීම; වරණය තුළ ලූපය – ධන සංඛ්‍යාවකට පමණක් වර්ග (එකට 1).

5Complete a trace table for the star program (4 rows) showing Row, how many times the inner loop runs, and what is printed. (3 marks)තරු වැඩසටහන (පේළි 4) සඳහා Row, ඇතුළු ලූපය ධාවනය වන වාර ගණන සහ මුද්‍රණය වන දේ පෙන්වන අනුරේඛන වගුවක් සම්පූර්ණ කරන්න. (ලකුණු 3) (3 marksලකුණු 3)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
Row 1 → 1 → *; Row 2 → 2 → ; Row 3 → 3 → *; Row 4 → 4 → **** (3 for all correct).Row 1 → 1 → *; Row 2 → 2 → ; Row 3 → 3 → *; Row 4 → 4 → **** (සියල්ල නිවැරදි නම් 3).
RowRowInner loop runs (times)ඇතුළු ලූපය ධාවනය (වාර)Printedමුද්‍රණය වූ දේ
1111**
2222****
3333******
4444********

🎮 Game🎮 ක්‍රීඩා

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

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

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

  • Nesting = a structure inside another.කැදැලි = ව්‍යුහයක් තුළ තවත් එකක්.
  • Nested IF: largest of three.කැදැලි IF: තුනෙන් විශාලතම.
  • Nested loop: inner loop runs fully each time.කැදැලි ලූපය: ඇතුළු ලූපය සෑම විටම සම්පූර්ණයෙන් ධාවනය වේ.
  • Inner runs = outer × inner (fixed sizes).ඇතුළත ධාවන = පිටත × ඇතුළු (ස්ථාවර ප්‍රමාණ).
  • IF inside a loop: count passes.ලූපයක් තුළ IF: සමත් ගණන් කිරීම.
  • Loop inside an IF: run only when valid.IF එකක් තුළ ලූපය: වලංගු නම් පමණක් ධාවනය.
  • Indent every level; close inner first.සෑම මට්ටමක්ම ඉන්ඩෙන්ට් කරන්න; ඇතුළත මුලින් වසන්න.
  • Pascal: begin … end groups statements.Pascal: begin … end ප්‍රකාශ කාණ්ඩ කරයි.

Downloadsබාගත කිරීම්

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

Next noteඊළඟ සටහන 1.9 →

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