© 2026 schoolict.net (Ruwan Mangala Suraweera)
1.6 Selection: If–EndIf, If–Else–EndIf and Caseවරණය: If–EndIf, If–Else–EndIf සහ Case
G.C.E. O/L Grade 11 ICT · Lesson 1G.C.E. O/L ICT · 11 ශ්රේණිය · පාඩම 1
In this videoමේ වීඩියෝවේ
- Selection chooses a path with a condition.වරණය කොන්දේසියකින් මාර්ගයක් තෝරයි.
- IF … THEN runs only when True.IF … THEN True නම් පමණක් ධාවනය වේ.
- IF … ELSE chooses one of two paths.IF … ELSE මාර්ග දෙකෙන් එකක් තෝරයි.
- ELSE IF ladder for many ranges (grades).පරාස බොහොමයකට ELSE IF පඩිපෙළ (ශ්රේණි).
- CASE chooses by a value (day number).CASE අගයක් අනුව තෝරයි (දින අංකය).
Notesසටහන්
Syllabus 10.6. Selection lets a program make decisions. There are three forms: If–EndIf (do something only when a condition is true), If–Else–EndIf (choose between two paths) and Case (choose one of many options). For each one we go flowchart → pseudocode → Pascal and Python code.විෂය නිර්දේශය 10.6. වරණය මගින් වැඩසටහනකට තීරණ ගත හැක. ආකාර තුනක් ඇත: If–EndIf (කොන්දේසිය සත්ය වූ විට පමණක් යමක් කිරීම), If–Else–EndIf (මාර්ග දෙකකින් එකක් තේරීම) සහ Case (විකල්ප බොහොමයකින් එකක් තේරීම). එක් එකක් සඳහා ගැලීම් සටහන → ව්යාජ කේතය → Pascal සහ Python කේතය ලෙස යමු.
1. If–EndIf (one-way selection)1. If–EndIf (ඒක-මාර්ග වරණය)
If the condition is True, the statements inside run. If it is False, they are skipped and the program continues after ENDIF.කොන්දේසිය සත්ය නම් ඇතුළත ප්රකාශ ක්රියාත්මක වේ. අසත්ය නම් ඒවා මඟ හැරී ENDIF ට පසුව වැඩසටහන දිගටම යයි.
📝 General pseudocodeසාමාන්ය ව්යාජ කේතය
IF condition THEN statements ENDIF
Example: a shop in Galle gives a 10% discount when the bill is more than Rs. 5000.උදාහරණය: ගාල්ලේ කඩයක් බිල රු. 5000 ට වැඩි විට 10% වට්ටමක් දෙයි.
📝 Pseudocodeව්යාජ කේතය (Pseudocode)
BEGIN INPUT Total Discount = 0 IF Total > 5000 THEN Discount = Total * 10 / 100 ENDIF DISPLAY Discount, Total - Discount END
program BillDiscount; var total, discount: integer; begin write('Enter bill total (Rs.): '); readln(total); discount := 0; if total > 5000 then discount := total * 10 div 100; writeln('Discount = Rs. ', discount); writeln('Amount to pay = Rs. ', total - discount); end.
total = int(input("Enter bill total (Rs.): ")) discount = 0 if total > 5000: discount = total * 10 // 100 print("Discount = Rs.", discount) print("Amount to pay = Rs.", total - discount)
▶ Sample runනියැදි ධාවනය 1 · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter bill total (Rs.): 6500 Discount = Rs. 650 Amount to pay = Rs. 5850
▶ Sample runනියැදි ධාවනය 2 · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter bill total (Rs.): 3000 Discount = Rs. 0 Amount to pay = Rs. 3000
2. If–Else–EndIf (two-way selection)2. If–Else–EndIf (ද්වි-මාර්ග වරණය)
Exactly one of two groups of statements runs: the THEN part if the condition is True, the ELSE part if it is False.ප්රකාශ කණ්ඩායම් දෙකෙන් හරියටම එකක් ක්රියාත්මක වේ: කොන්දේසිය සත්ය නම් THEN කොටස, අසත්ය නම් ELSE කොටස.
📝 General pseudocodeසාමාන්ය ව්යාජ කේතය
IF condition THEN statements A ELSE statements B ENDIF
📝 Pseudocodeව්යාජ කේතය (Pseudocode)
BEGIN INPUT N IF N MOD 2 = 0 THEN DISPLAY "Even" ELSE DISPLAY "Odd" ENDIF END
program EvenOdd; var n: integer; begin write('Enter a number: '); readln(n); if n mod 2 = 0 then writeln(n, ' is even') else writeln(n, ' is odd'); end.
n = int(input("Enter a number: ")) if n % 2 == 0: print(n, "is even") else: print(n, "is odd")
▶ Sample runනියැදි ධාවනය 1 · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter a number: 14 14 is even
▶ Sample runනියැදි ධාවනය 2 · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter a number: 7 7 is odd
3. Many choices: IF … ELSE IF (O/L grades)3. විකල්ප බොහොමයක්: IF … ELSE IF (O/L ශ්රේණි)
When there are more than two paths, we check conditions one after another. The first True condition wins and the rest are skipped. Sri Lankan O/L grades: A ≥ 75, B ≥ 65, C ≥ 50, S ≥ 35, otherwise W.මාර්ග දෙකකට වඩා ඇති විට, කොන්දේසි එකින් එක පරීක්ෂා කරමු. පළමු සත්ය කොන්දේසිය ජය ගන්නා අතර ඉතිරිය මඟ හැරේ. ශ්රී ලංකා O/L ශ්රේණි: A ≥ 75, B ≥ 65, C ≥ 50, S ≥ 35, නැතිනම් W.
📝 Pseudocodeව්යාජ කේතය (Pseudocode)
BEGIN INPUT Marks IF Marks >= 75 THEN Grade = "A" ELSE IF Marks >= 65 THEN Grade = "B" ELSE IF Marks >= 50 THEN Grade = "C" ELSE IF Marks >= 35 THEN Grade = "S" ELSE Grade = "W" ENDIF DISPLAY Grade END
program MarksToGrade; var marks: integer; grade: char; begin write('Enter marks: '); readln(marks); if marks >= 75 then grade := 'A' else if marks >= 65 then grade := 'B' else if marks >= 50 then grade := 'C' else if marks >= 35 then grade := 'S' else grade := 'W'; writeln('Grade: ', grade); end.
marks = int(input("Enter marks: ")) if marks >= 75: grade = "A" elif marks >= 65: grade = "B" elif marks >= 50: grade = "C" elif marks >= 35: grade = "S" else: grade = "W" print("Grade:", grade)
▶ Sample runනියැදි ධාවනය 1 · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter marks: 82 Grade: A
▶ Sample runනියැදි ධාවනය 2 · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter marks: 58 Grade: C
▶ Sample runනියැදි ධාවනය 3 · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter marks: 30 Grade: W
4. Case (multi-way selection)4. Case (බහු-මාර්ග වරණය)
When one variable is compared with many fixed values (1, 2, 3…), Case is shorter and clearer than many IFs. Pascal uses case … of … else … end. Python (3.10 and later) uses match … case; case _ means “anything else”.එක් විචල්යයක් ස්ථාවර අගයන් (1, 2, 3…) බොහොමයක් සමඟ සසඳන විට, IF බොහොමයකට වඩා Case කෙටි සහ පැහැදිලිය. Pascal case … of … else … end භාවිත කරයි. Python (3.10 සහ පසු) match … case භාවිත කරයි; case _ යනු “වෙනත් ඕනෑම දෙයක්”.
📝 Pseudocodeව්යාජ කේතය (Pseudocode)
BEGIN INPUT Day CASE Day OF 1 : DISPLAY "Sunday" 2 : DISPLAY "Monday" 3 : DISPLAY "Tuesday" 4 : DISPLAY "Wednesday" 5 : DISPLAY "Thursday" 6 : DISPLAY "Friday" 7 : DISPLAY "Saturday" OTHERWISE : DISPLAY "Invalid day" ENDCASE END
program DayName; var day: integer; begin write('Enter day number (1-7): '); readln(day); case day of 1: writeln('Sunday'); 2: writeln('Monday'); 3: writeln('Tuesday'); 4: writeln('Wednesday'); 5: writeln('Thursday'); 6: writeln('Friday'); 7: writeln('Saturday'); else writeln('Invalid day'); end; end.
day = int(input("Enter day number (1-7): ")) match day: case 1: print("Sunday") case 2: print("Monday") case 3: print("Tuesday") case 4: print("Wednesday") case 5: print("Thursday") case 6: print("Friday") case 7: print("Saturday") case _: print("Invalid day")
▶ Sample runනියැදි ධාවනය 1 · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter day number (1-7): 3 Tuesday
▶ Sample runනියැදි ධාවනය 2 · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter day number (1-7): 9 Invalid day
5. From flowchart to code – the steps5. ගැලීම් සටහනේ සිට කේතය දක්වා – පියවර
Key Wordsප්රධාන පද
Sample Q&Aආදර්ශ ප්රශ්න සහ පිළිතුරු
1What is the difference between If–EndIf and If–Else–EndIf?If–EndIf සහ If–Else–EndIf අතර වෙනස කුමක්ද?
2For a bill of Rs. 6500, what discount does the program give?රු. 6500 බිලක් සඳහා වැඩසටහන දෙන වට්ටම කීයද?
3What grade does 58 get?58 ට ලැබෙන ශ්රේණිය කුමක්ද?
4When is Case better than many IFs?IF බොහොමයකට වඩා Case හොඳ වන්නේ කවදාද?
5What does the day program display for 9?day වැඩසටහන 9 සඳහා පෙන්වන්නේ කුමක්ද?
6Why must we test both paths of an IF?IF එකක මාර්ග දෙකම පරීක්ෂා කළ යුත්තේ ඇයි?
MCQබහුවරණ ප්රශ්න
Choose the correct answer for each question.සෑම ප්රශ්නයකටම නිවැරදි පිළිතුර තෝරන්න.
1In If–EndIf, when the condition is False…If–EndIf හි කොන්දේසිය අසත්ය වූ විට…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Skipped.මඟ හැරේ.
2If–Else–EndIf always runs…If–Else–EndIf සැමවිටම ධාවනය කරන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
One of two.දෙකෙන් එකක්.
3Bill Rs. 6500 with 10% discount over Rs. 5000. Amount to pay is…රු. 5000 ට වැඩි නම් 10% වට්ටම සමඟ රු. 6500 බිල. ගෙවිය යුත්තේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
6500 − 650.6500 − 650.
4Bill Rs. 3000 in the same program. Discount is…එම වැඩසටහනේම රු. 3000 බිල. වට්ටම…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Not over 5000.5000 ට වැඩි නැත.
5The even/odd program shows “7 is odd” because…even/odd වැඩසටහන “7 is odd” පෙන්වන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Remainder 1.ශේෂය 1.
6The O/L grade for 82 marks is…ලකුණු 82 සඳහා O/L ශ්රේණිය…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
≥ 75.≥ 75.
7The O/L grade for 30 marks is…ලකුණු 30 සඳහා O/L ශ්රේණිය…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
< 35.< 35.
8The O/L grade for 66 marks is…ලකුණු 66 සඳහා O/L ශ්රේණිය…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
65–74.65–74.
9Choosing a day name from a day number 1–7 is best done with…දින අංකය 1–7 න් දින නාමය තේරීමට වඩාත් සුදුසු…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Many fixed values.ස්ථාවර අගයන් බොහොමයක්.
10Python’s case statement uses the words…Python හි case ප්රකාශය භාවිත කරන වචන…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Python 3.10+.Python 3.10+.
11In Pascal, what must NOT come just before else?Pascal හි else ට කෙළින්ම පෙර නොතිබිය යුත්තේ කුමක්ද?
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Semicolon ends the if.Semicolon if අවසන් කරයි.
12Python groups the statements inside an if by…Python if එකක් තුළ ප්රකාශ කාණ්ඩ කරන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C
Indentation.ඉන්ඩෙන්ටේෂන්.
13In a flowchart, the Yes branch of a decision becomes the… part.ගැලීම් සටහනක තීරණයක ඔව් ශාඛාව වන්නේ … කොටසයි.
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B
Yes → THEN.ඔව් → THEN.
14In Pascal case, the part for “any other value” is written…Pascal case හි “වෙනත් ඕනෑම අගයක්” සඳහා කොටස ලියන්නේ…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D
Pascal: else.Pascal: else.
15To test a pass/fail program fully, use…pass/fail වැඩසටහනක් සම්පූර්ණයෙන් පරීක්ෂා කිරීමට භාවිත කරන්න…
✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A
Test both paths.මාර්ග දෙකම පරීක්ෂා කරන්න.
MCQ answer keyMCQ පිළිතුරු
- D – Skipped.මඟ හැරේ.
- B – One of two.දෙකෙන් එකක්.
- C – 6500 − 650.6500 − 650.
- A – Not over 5000.5000 ට වැඩි නැත.
- B – Remainder 1.ශේෂය 1.
- C – ≥ 75.≥ 75.
- A – < 35.< 35.
- B – 65–74.65–74.
- A – Many fixed values.ස්ථාවර අගයන් බොහොමයක්.
- C – Python 3.10+.Python 3.10+.
- D – Semicolon ends the if.Semicolon if අවසන් කරයි.
- C – Indentation.ඉන්ඩෙන්ටේෂන්.
- B – Yes → THEN.ඔව් → THEN.
- D – Pascal: else.Pascal: else.
- A – Test both paths.මාර්ග දෙකම පරීක්ෂා කරන්න.
Structured Questionsව්යුහගත ප්රශ්න
1A shop gives a 10% discount when the bill is more than Rs. 5000. (i) Draw the flowchart. (ii) Write the pseudocode. (iii) Find the amount to pay for Rs. 6500 and Rs. 3000. (6 marks)බිල රු. 5000 ට වැඩි විට කඩයක් 10% වට්ටමක් දෙයි. (i) ගැලීම් සටහන අඳින්න. (ii) ව්යාජ කේතය ලියන්න. (iii) රු. 6500 සහ රු. 3000 සඳහා ගෙවිය යුතු මුදල සොයන්න. (ලකුණු 6) (6 marksලකුණු 6)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
📝 Pseudocodeව්යාජ කේතය (Pseudocode)
BEGIN INPUT Total Discount = 0 IF Total > 5000 THEN Discount = Total * 10 / 100 ENDIF DISPLAY Discount, Total - Discount END
2Write a program (Pascal or Python) to input a number and display whether it is even or odd. (4 marks)සංඛ්යාවක් ආදානය කර එය ඉරට්ටේද ඔත්තේද යන්න පෙන්වන වැඩසටහනක් (Pascal හෝ Python) ලියන්න. (ලකුණු 4) (4 marksලකුණු 4)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
program EvenOdd; var n: integer; begin write('Enter a number: '); readln(n); if n mod 2 = 0 then writeln(n, ' is even') else writeln(n, ' is odd'); end.
n = int(input("Enter a number: ")) if n % 2 == 0: print(n, "is even") else: print(n, "is odd")
▶ Sample runනියැදි ධාවනය 1 · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter a number: 14 14 is even
▶ Sample runනියැදි ධාවනය 2 · same output in Pascal and Python (typed input in yellow)Pascal සහ Python දෙකෙහිම එකම ප්රතිදානය (ටයිප් කළ ආදානය කහ පාටින්)
Enter a number: 7 7 is odd
3Write pseudocode that inputs marks and displays the O/L grade (A ≥ 75, B ≥ 65, C ≥ 50, S ≥ 35, W otherwise). (5 marks)ලකුණු ආදානය කර O/L ශ්රේණිය පෙන්වන ව්යාජ කේතය ලියන්න (A ≥ 75, B ≥ 65, C ≥ 50, S ≥ 35, නැතිනම් W). (ලකුණු 5) (5 marksලකුණු 5)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
📝 Pseudocodeව්යාජ කේතය (Pseudocode)
BEGIN INPUT Marks IF Marks >= 75 THEN Grade = "A" ELSE IF Marks >= 65 THEN Grade = "B" ELSE IF Marks >= 50 THEN Grade = "C" ELSE IF Marks >= 35 THEN Grade = "S" ELSE Grade = "W" ENDIF DISPLAY Grade END
4(i) When is a Case statement used? (1 mark)
(ii) Write a Case statement in pseudocode that displays “Sunday” for 1, “Monday” for 2 and “Invalid day” otherwise. (3 marks)(i) Case ප්රකාශයක් භාවිත කරන්නේ කවදාද? (ලකුණු 1)
(ii) 1 සඳහා “Sunday”, 2 සඳහා “Monday” සහ නැතිනම් “Invalid day” පෙන්වන Case ප්රකාශයක් ව්යාජ කේතයෙන් ලියන්න. (ලකුණු 3) (4 marksලකුණු 4)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
5Find the error in this Pascal code and correct it: if Mark >= 35 then writeln(‘Pass’); else writeln(‘Fail’); (2 marks)මෙම Pascal කේතයේ දෝෂය සොයා නිවැරදි කරන්න: if Mark >= 35 then writeln(‘Pass’); else writeln(‘Fail’); (ලකුණු 2) (2 marksලකුණු 2)
Show model answerආදර්ශ පිළිතුර පෙන්වන්න
🎮 Game🎮 ක්රීඩා
Summary & Downloadsසාරාංශය සහ බාගත කිරීම්
Key pointsප්රධාන කරුණු
- Selection = making a decision.වරණය = තීරණයක් ගැනීම.
- If–EndIf: do it or skip it.If–EndIf: කරන්න හෝ මඟ හරින්න.
- If–Else–EndIf: one of two paths.If–Else–EndIf: මාර්ග දෙකෙන් එකක්.
- ELSE IF chains check conditions in order.ELSE IF දාම කොන්දේසි පිළිවෙළින් පරීක්ෂා කරයි.
- Case: one of many fixed values.Case: ස්ථාවර අගයන් බොහොමයකින් එකක්.
- Pascal: case … of; Python: match … case.Pascal: case … of; Python: match … case.
- Pascal: no ; before else. Python: indent.Pascal: else ට පෙර ; නැත. Python: ඉන්ඩෙන්ට්.
- Test every path with test data.පරීක්ෂණ දත්ත මගින් සෑම මාර්ගයක්ම පරීක්ෂා කරන්න.
