3 basic programming structures

Sequence

  • usual flow in the program (very basic programs) Selection
  • A point in the program where we compare 2 values
  • Always returns true or false
  • IF statements decides between 2 or more true or false options
  • Switch/case statement chooses one of several options
  • Logic statement usually contains relational expression Repetition
  • Block of code is repeated multiple times (more than once)
  • An end condition is set and it continues to execute until that condition is met
  • For loop - Repeats the code a set number of times
    • 3 things control: Index declaration, test condition, incrementation
  • While loop - Repeats the code until a condition is met (indefinetly)
  • Do while loop - tests the condition at the end of the loop (loop executes at least once)
    Format:
    
    do {
    
    } while (condition);