Condition VS Switch

Switch

  • A switch block has several possible execution paths
  • With a switch block you are going to check on one specific variable
  • A switch block is build out of three parts
    • You have the variable you are going to check on
    • Inside the switch block you have “cases” these are the actions you are going to execute if the variable is equals to the “check value”
    • At the end of the switch block is the “Default case” in this case you will define what will happen if none of the cases match the variable value.
switch

Condition

  • With conditions we are going to check “if” a condition is “true” of “false”
  • You can check if a value is
    • equals
    • not equals
    • greater than
    • less than
    • less than or equal to
    • contains
    • does not contain
    • in Empty
    • isn’t empty
    • Starts with
    • doesn’t start with
    • ends with
    • doesn’t end with
  • With a conditions you can say “If this is true, do this. Else do this”
  • With conditions you can check on multiple variables at the same time by using “and” and “or”
pipelines2

When to use what?

If you are going to check on one variable and its either going to be true or false you can best use a conditionIf you are going to check on one variable and it can have multiple values you can best use a switchIf you are going to check on multiple variables you can best use a condition

Plaats een reactie

Maak een blog op WordPress.com.

Omhoog ↑