Course Content
Paper 2 – Problem Solving Approach -Practical
0/102
Past Paper-2 May/June 2025
Past Paper-1 May/June 2025
Download Files
0/1
Olevel : Computer Science 2210 / IGCSE 0478 : Recorded

IF…THEN…ENDIF(OneWay)

Reading: Read content other than video.

In today’s lesson, we will learn about the IF…THEN…ENDIF construct in pseudocode. This structure executes a block of code only if a specific condition is true. If the condition is false, the program simply skips that block and continues.

Look at the structure on the screen — it will only produce output if the value of A is greater than 10; otherwise, the computer will skip this block.

Let’s take another example: a newborn baby naturally performs one action — crying — in response to a certain condition. For instance, if the baby is hungry, it cries to get the mother’s attention. Similarly, this construct handles one specific task based on a given condition.

Now let’s take another example. Say I want to check three conditions for a number:
If the number is greater than 0, that means it’s a positive number.
If the number is exactly equal to 0, then we’ll write zero.
And if the number is less than 0, that means it’s a negative number.

So, using a one-way construct, I’ll need to make three separate blocks — one for positive, one for zero, and one for negative.

Remember students, if you have five conditions in your exam and you’re using a one-way construct, you’ll need five blocks, each handling one condition. That’s how the one-way construct works.

We are learning how to check whether a number is positive, zero, or negative using simple IF statements in pseudocode. The program starts with the line DECLARE NUMBER : INTEGER, which means we are creating a variable named NUMBER to store an integer value. Next, the line OUTPUT "ENTER NUMBER:" displays a message asking the user to input a number. The INPUT NUMBER command then takes the number entered by the user and stores it in the variable NUMBER.

Now the program begins checking conditions using IF constructs. The first condition IF NUMBER > 0 THEN OUTPUT "POSITIVE NUMBER" ENDIF checks whether the number is greater than zero. If it is, the program prints “POSITIVE NUMBER” to show that the number is positive. If the condition is not true, the program skips this block and moves on. The next condition IF NUMBER = 0 THEN OUTPUT "ZERO NUMBER" ENDIF checks if the number is equal to zero. If this condition is true, the program outputs “ZERO NUMBER”. Finally, the third condition IF NUMBER < 0 THEN OUTPUT "NEGATIVE NUMBER" ENDIF checks if the number is less than zero. If so, it displays “NEGATIVE NUMBER”.

Each of these IF statements works independently. The program checks all three conditions one by one, and only the block with a true condition will execute. For example, if the user enters 5, the output will be “POSITIVE NUMBER”; if the input is 0, the output will be “ZERO NUMBER”; and if the input is –3, the output will be “NEGATIVE NUMBER”. This simple program helps beginners understand how one-way selection constructs work — executing a specific block of code only when its condition is true.

 

Press the “Mark as Complete” button to finish the lecture.

You cannot copy content of this page