Year 11 Exam  >  Year 11 Notes  >  Computer for GCSE/IGCSE  >  Selection

Selection | Computer for GCSE/IGCSE - Year 11 PDF Download

What is selection?

Selection in programming is a concept enabling the execution of various instructions depending on specific conditions. It involves two main types of selection statements: IF statements and CASE statements.

If Statements

IF statements enable the execution of a set of instructions if a condition is met. They follow this syntax:
IF condition
  THEN
    instructions
ENDIF
Pseudocode example:
x← 5
IF x > 0
THEN
    PRINT "x is positive"
ENDIF

Python example:
x = 5
if x > 0:
    print("x is positive")

Java example:
int x = 5;
if (x > 0) {
System.out.println("x is positive");
}

Visual Basic example:
Dim x As Integer = 5
If x > 0 Then
Console.WriteLine("x is positive")
End If

If else Statements

If-else statements are utilized to run a specific set of instructions when a condition is true and another set when it's false. They follow this syntax:
IF condition
  THEN
    Instructions
ELSE
    Instructions
ENDIF

Pseudocode example:
x ← 5
IF x > 0
THEN
    PRINT "x is positive"
ELSE
    PRINT “x is negative”
ENDIF

Python example:
x = 5
if x > 0:
    print("x is positive")
else:
    print("x is negative")

Java example:
int x = 5;
if (x > 0) {
System.out.println("x is positive");
} else {
System.out.println("x is negative");
}

Visual Basic example:
Dim x As Integer = 5
If x > 0 Then
Console.WriteLine("x is positive")
Else
Console.WriteLine("x is negative")
End If

IF ELSE IF Statements

Else-if statements are employed to assess multiple conditions and execute distinct instructions for each condition. They follow this syntax:
IF condition
  THEN
    Instructions
ELSE IF condition
  THEN
    Instructions
  ELSE
    Instructions
ENDIF

Pseudocode example:
x ←  5
IF x > 0
THEN
    PRINT "x is positive"
ELSE IF x < 0
THEN
    PRINT “x is negative”
ELSE
    PRINT “x is 0”
ENDIF

Python example:
x = 5
if x > 0:
    print("x is positive")
elif x < 0:
    print("x is negative")
else:
    print("x is 0")

Java example:
int x = 5;
if (x > 0) {
System.out.println("x is positive");
} else if (x < 0) {
System.out.println("x is negative");
} else {
System.out.println("x is 0");
}

Visual Basic example:
Dim x As Integer = 5
If x > 0 Then
Console.WriteLine("x is positive")
ElseIf x < 0 Then
Console.WriteLine("x is negative")
Else
Console.WriteLine("x is 0")
End If

Case Statements

CASE statements enable the execution of different sets of instructions depending on the value of a variable. They follow this syntax:
CASE OF variable
    value1: instructions
   value2: instructions
    ...
    OTHERWISE instructions
END CASE

Pseudocode example:
CASE OF number
1: PRINT "Monday"
2: PRINT "Tuesday"
3: PRINT “Wednesday”
4: PRINT “Thursday”
5: PRINT “Friday”
6: PRINT “Saturday”
7: PRINT “Sunday”
OTHERWISE PRINT "Invalid number"
END CASE

Python example:
match (number)
case 1:
print "Monday";
case 2:
print "Tuesday";
case 3:
print "Wednesday";
case 4:
print "Thursday";
case 5:
print "Friday";
case 6:
print "Saturday";
case 7:
print "Sunday";
case _:
print "Invalid number";

Java example:
switch (number) {
case 1:
return "Monday";
case 2:
return "Tuesday";
case 3:
return "Wednesday";
case 4:
return "Thursday";
case 5:
return "Friday";
case 6:
return "Saturday";
case 7:
return "Sunday";
default:
return "Invalid number";
}

Visual Basic example:
Select Case number
Case 1
Return "Monday"
Case 2
Return "Tuesday"
Case 3
Return "Wednesday"
Case 4
Return "Thursday"
Case 5
Return "Friday"
Case 6
Return "Saturday"
Case 7
Return "Sunday"
Case Else
Return "Invalid number"
End Select

The document Selection | Computer for GCSE/IGCSE - Year 11 is a part of the Year 11 Course Computer for GCSE/IGCSE.
All you need of Year 11 at this link: Year 11
92 docs|30 tests

Top Courses for Year 11

92 docs|30 tests
Download as PDF
Explore Courses for Year 11 exam

Top Courses for Year 11

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Selection | Computer for GCSE/IGCSE - Year 11

,

Previous Year Questions with Solutions

,

Free

,

Semester Notes

,

Extra Questions

,

practice quizzes

,

study material

,

Summary

,

past year papers

,

Exam

,

video lectures

,

Sample Paper

,

Important questions

,

MCQs

,

Selection | Computer for GCSE/IGCSE - Year 11

,

mock tests for examination

,

Viva Questions

,

ppt

,

Objective type Questions

,

Selection | Computer for GCSE/IGCSE - Year 11

,

shortcuts and tricks

,

pdf

;