Skip to content
SPM Tuition
Guide · Asas Sains Komputer

Form 2 Asas Sains Komputer guide

You can read a short program but cannot say what it prints for a given input.

Form 2 Asas Sains Komputer (ASK) comes down to two habits: tracing a short program to find what it prints, and choosing test inputs that reveal what the program forgets. This page teaches both with two small original programs on paper.

It sits inside the subject guides and is written for pupils whose school offers ASK in Form 2 under KSSM. It is not an offer for new Form 1 pupils in 2027, and it is a different subject from Form 4 Computer Science, so your school’s timetable and scheme of work decide what your class covers.

How do I trace a program line by line?

Trace means to act as the computer: take one input, run each line in order and write down every value that changes. Here is an original canteen program. The pseudocode keywords are only one style, and your textbook may use other words.

INPUT price
INPUT member
IF member = "Y" THEN
    price ← price − 2
END IF
IF price > 10 THEN
    PRINT "Pay by e-wallet"
ELSE
    PRINT "Pay cash"
END IF
PRINT price

Try price 12 with member “Y”. The first IF is true, so price becomes 10. The second IF asks 10 > 10, which is false, so the program prints “Pay cash” and then 10.

price in member in price after the first IF output
12 Y 10 Pay cash, 10
12 N 12 Pay by e-wallet, 12
11 Y 9 Pay cash, 9

What is the usual tracing mistake?

The usual mistake is to answer the second IF with the original price of 12 and print “Pay by e-wallet” for the first row. That is wrong because line 4 already changed price to 10, and every later line uses the current value, not the starting value. A column that records price after each change prevents it.

How do I choose test inputs that expose a missing branch?

A test input is a value you choose before running the program, together with the output you expect. Here is a second original program for ticket types, meant to give Child under 13, Adult from 13 to 59 and Senior from 60.

INPUT age
IF age < 13 THEN
    PRINT "Child ticket"
ELSE IF age >= 60 THEN
    PRINT "Senior ticket"
END IF

Ages 5, 8 and 10 all print “Child ticket”, which looks correct, but they test one branch three times. Age 30 prints nothing, so the Adult branch is missing. Add the boundaries 12, 13, 59 and 60 as well.

A good set is 5, 12, 13, 30, 59, 60 and 70. The fix is an ELSE that prints “Adult ticket” for every age that fits neither condition.

Where should I go next?

Do the eight questions in Form 2 Asas Sains Komputer practice with fresh programs. Then read the Form 3 guide for comparing searches and correcting a logic error, and see the Form 2 overview for your other subjects.

Computer room work and any tool your school uses stay with the school. These pages train the paper skills that make that work easier.

If tracing a program by hand still leaves you unsure what it prints, Asas Sains Komputer tuition pairs you with a teacher who walks through the variable values step by step until you can do it silently.

Common questions

What is a trace table and why use one?

A trace table lists each input and the value of every variable after each line runs, ending with the output. It stops you from guessing the answer in your head. When the final output is wrong, the table shows the first line where your working went off.

How many test inputs does a short program need?

Pick at least one input for each branch, one input that fits no branch, and the values on each side of every boundary. For an if with a limit of 13, test 12 and 13. Five or six well-chosen inputs beat twenty similar ones.

Is this the same as SPM Computer Science?

No. Asas Sains Komputer is a KSSM lower-secondary subject taught in Forms 2 and 3 where the school offers it. Sains Komputer is a separate Form 4 and Form 5 subject, so check which one your school timetable shows.

My school uses Malay words in pseudocode. Does that matter?

The logic is the same. JIKA and MAKA do the job of IF and THEN. Learn the keywords your textbook uses and apply the same tracing steps to them.

Want to work through this topic with a teacher? We can explain the steps, look at your attempted questions and help you decide what to practise next.

If you have a question or a piece of working, you can share it.

  • Online one-to-one lessons for your child with an experienced teacher.
  • Your first class is a one-hour trial, from RM50. The fee is agreed before you book.
  • Happy with the teacher? Continue with lessons of about 1.5 hours. If not, ask for another teacher.