Passer au contenu

interrupteur

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 = "sat" matches case "sat", logs Weekend and breaks; the other cases are skipped

Fiche de cours

Se connecter ou créer un compte

IGCSE, A-Level & AP