General and Web Programming Fundamentals
  • Introduction
  • Program creation and design
    • Program design
      • Algorithms
      • Pseudocode
    • Programming conventions
    • Writing programs
      • Source code editors
      • Integrated Development Environments
      • Code repositories/Version control
      • Compilers/Interpreters
  • Programming Fundamentals
    • Operators
      • Arithmetic
      • Logical
      • Assignment
    • Constants and Variables
    • Datatypes
      • Primitive Datatypes
        • Character
        • Integer
        • Boolean
        • Floating point
        • Nothing (Null)
      • Composite Datatypes
        • Arrays
        • Strings
        • Classes
        • Structs
      • Literals
    • Data structures
      • Lists
      • Queues
      • Stacks
      • Map/dictionary
      • Trees
      • Graphs
    • Control structures
      • Selection (Conditional)
        • If/Else
        • Ternary
        • Switch
      • Iteration (Loops)
        • For loops
        • While loops
        • Do-While loops
        • For-Each loops
    • Functions
      • Parameters and arguments
      • Lambda expressions
      • Higher Order Functions
    • Space and Time
    • Scope
    • Standard libraries
  • Programming Paradigms
    • Procedural (Imperative) Programming
    • Object-oriented programming
    • Functional Programming
    • Declarative Programming
    • Event Driven programming
  • Programming Languages
    • Short history of programming
    • Low-level programming languages
    • High-level programming languages
  • Web Development
    • What is the web?
      • Web browsers (clients)
      • Webservers (serving web pages)
      • W3C
    • Markup languages
      • HTML
        • HTML Tags
      • Cascading Style Sheets (CSS)
        • CSS Properties
      • XML
      • Markdown
    • Scripting Languages
      • JavaScript
      • TypeScript
    • JSON
    • JavaScript Frameworks
  • Acknowledgements
    • About the author(s)
  • License
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Programming Fundamentals
  2. Control structures

Selection (Conditional)

Selection Control Structure in Computer Programming

The selection control structure, also commonly referred to as the conditional control structure, is a fundamental concept in computer programming that enables a program to choose different paths of execution based on certain conditions. This structure is critical for making decisions in the code, allowing programs to behave dynamically and respond differently to various inputs or situations.

Definition

At its core, a selection control structure evaluates a condition (usually a comparison between two values or variables) and then directs the program flow to one or more paths based on the outcome of that evaluation. If the condition evaluates to true, one path of execution is followed; if false, another path is taken.

Main Types

  1. If Statement: The most basic form of selection, allowing for the execution of a block of code if a specified condition is true.

  2. If-Else Statement: Extends the if statement to provide an alternative path of execution if the condition is false.

  3. Switch Statement: Allows a variable to be tested for equality against a list of values, each with its own block of execution.

Importance

Using selection control structures makes it possible to create more flexible and powerful software applications. They are essential for tasks such as validating user input, making calculations based on dynamic data, and navigating through complex workflow processes. Without these structures, programs would be linear and much less capable of handling real-world complexities.

In summary, selection control structures are a cornerstone of computer programming, providing the necessary logic to make decisions and execute different code based on various conditions.

PreviousControl structuresNextIf/Else

Last updated 1 year ago

Was this helpful?