Subtopic Notes

E - Conditional/Selection Statements

9-11. Data Types and Structures, Programming

Conditional/Selection Statements

  • Allows a program to make decisions and execute different blocks of code based on certain conditions
  • Selects specific paths depending on the evaluation of boolean expressions

IF Statements

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

PSEUDOCODE

Pseudocode uses basic Cambridge-style keyword highlighting. Execution is not supported yet.

Editor — Pseudocode

Indentation: Lines are indented (usually by three spaces) to indicate that they are contained within a statement in a previous line. Notice how in the condition statements, after the conditions are given, there are some blank spaces

Else Statements

Executes one block if the condition is true, another if it's false.

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

PSEUDOCODE

Pseudocode uses basic Cambridge-style keyword highlighting. Execution is not supported yet.

Editor — Pseudocode

Elif Statements

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

PSEUDOCODE

Pseudocode uses basic Cambridge-style keyword highlighting. Execution is not supported yet.

Editor — Pseudocode

Nested If

The same program like above is now being done with nested if statements

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

Pass Statement (Do Nothing)

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

Logical Operators

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

CASE Statements

The match-case statement gives a more readable and efficient way to handle multiple conditions

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

PSEUDOCODE

Pseudocode uses basic Cambridge-style keyword highlighting. Execution is not supported yet.

Editor — Pseudocode