0% found this document useful (0 votes)
2 views2 pages

CS Notes Selection Control

The document discusses selection control structures in computer science, specifically the IF, IF...ELSE, and IF...ELSE IF constructs. It explains how these constructs are used to evaluate conditions and determine actions based on whether those conditions are true or false. Additionally, it includes examples in pseudocode and a grading scale for understanding the concepts better.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

CS Notes Selection Control

The document discusses selection control structures in computer science, specifically the IF, IF...ELSE, and IF...ELSE IF constructs. It explains how these constructs are used to evaluate conditions and determine actions based on whether those conditions are true or false. Additionally, it includes examples in pseudocode and a grading scale for understanding the concepts better.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computer Science

Marchwood Senior School · Selection Control Structures

Grading Scale

Marks Grade
75 – 100 A
60 – 74 B
50 – 59 C
Less than 50 F

1. Selection Control

Selection control is also called branching or the IF construct.

The IF Construct
• When you use the IF construct, you should specify the condition along with the course of action to
be taken if the condition is True.
• The condition should always evaluate to either True or False.
• The IF construct does not specify what is done if the condition evaluates to False.

Example — Pseudocode (check if a number is positive):


Output "Enter any number"
Read number
IF number > 0 THEN
Output "number is positive"
END IF

2. The IF…ELSE Construct

This construct allows you to specify a course of actions to be taken if the condition evaluates to False.

Normally the IF…ELSE construct is regarded as one, since the ELSE part is optional.
Meaning: you are not required to include it — IF…ELSE is optional.

Example — Pseudocode (positive or negative check):


Output "Enter any number"
Read number
IF number > 0 THEN
Output "number is positive"
ELSE
Output "number is not positive"
END IF

NB: We did not write the number itself because it may be zero (0).

3. The IF…ELSE IF Construct

Sometimes we have several conditions and the appropriate course of action must be taken for each.

When each condition is true, that action is performed.

In cases where we cannot use IF…ELSE (because each condition may be True or False), we use
IF…ELSE IF.

Example — Pseudocode (grade your marks):


Output "Enter your marks"
Read marks
IF marks >= 75 THEN
Output "Grade A"
ELSE IF marks >= 60 THEN
Output "Grade B"
ELSE IF marks >= 50 THEN
Output "Grade C"
ELSE
Output "Grade F"
END IF

Summary: Construct Comparison

Construct Purpose ELSE required?


IF Action when condition is True No
IF…ELSE Action for True AND False Yes
IF…ELSE IF Multiple conditions Optional

Marchwood Senior School — Computer Science Notes

You might also like