Saltar al contenido

switch

English

switch picks a case

  • switch compares one value against several possible matches, called cases.
  • It is a tidy alternative to a long if … else if chain that tests the same variable.
  • default runs when no case matches, like a final else.

day is "sat", so switch runs case "sat", logs Weekend and break leaves the switch; without break it would fall through into the next case

Material

Iniciar sesión o crear cuenta

IGCSE, A-Level & AP