Bits of Bytes.co

IGCSE / GCSE Computer Science

  • Home
  • 1 - Theory of Computer Science
  • 2 - Practical Problem Solving and Programming
  • Pre-Release Material
    • 2018 June >
      • 22 >
        • 22 - Cow Task
        • 22 - Task 1
        • 22 - Task 2
        • 22 - Task 3
  • 1 - Computer Systems (2023)
Picture
MENU
  • Home
  • 1 - Theory of Computer Science
  • 2 - Practical Problem Solving and Programming
  • Pre-Release Material
    • 2018 June >
      • 22 >
        • 22 - Cow Task
        • 22 - Task 1
        • 22 - Task 2
        • 22 - Task 3
  • 1 - Computer Systems (2023)
2 - Practical Problem Solving & Programming / Selection


Selection


An effective computer program is one that can adapt or react to information that it is given. The ability for a program to decide what action to take based on a certain condition opens up huge potential for the usefulness of algorithms.

Selection

In programming, the term selection means that the program can choose to run different commands based on a condition being true or false.  For example if a user enters their age into a drivers license system and their age is less than 17, the program will tell them that they are too young.  If the users age is 17 or older then the user can be prompted with further instructions to apply for a license.

​There are two ways to achieve selection these are IF statements and Select Case statements
IF Statement

    
Case Statement

    

  • IF Statements
  • SELECT CASE
<
>

IF Statements

If statements are a very simple but effective concept...

IF something is true > Do something
Else
​Do something else
Picture

IF - Syntax

The CAIE recommended syntax for IF statements is as follows:​
IF Statement

    
IF with ELSE IF Statement

    

Select Case Statements

Case statements are particularly useful when there are many possible conditions.  They allow for a more efficient (less lines of code) algorithm:
Picture

Picture

CASE - Syntax

The CAIE recommended syntax for CASE statements is as follows:​
SELECT CASE Statement

    

Vertical Divider
Est. 2015 - Copyright © 2020