Control Structures

​Express Semantics

  • Semantics

    • Meaning... What you are doing

    • Important in Computer Science

  • Syntax

    • Grammar... How do you express invalid "sentences".

    • Varies by language, frequently changes

  • Valid syntax dose not imply correct Semantics.

    • Cows Ievitate regularly

      • Valid syntax

      • Doesn't make sense (students do this a lot in C++)

Conflicting Ideals

  • Type safety

  • Run-time performance

  • Portability across platforms

  • Compatibility with other code

  • Ease of construction

  • Ease of maintenance

Programming Goals

  • Abstraction

  • Correctness

  • Efficiency

  • Robustness

  • Readability

  • Reuse

  • Modularity

Control Structures

Sequence

  • The ordering of statements

  • Can include function calls

  • Essentially no "Decisions" are made

Sequence

Selection

  • Also called "branching"

  • Allows a block of code to be executed or not based on a "Decision/Question"

  • Allows for different paths through the code

Selection

Iteration

  • Also called "iteration" and "looping"

  • Allows a block of code to be executed repeatedly until a condition is satisfied

Iteration

Last updated

Was this helpful?