Id: switch.tex,v 1.2 2003/11/20 14:09:12 joe Exp
switch (n) { case (1) : { Block-A; break; } case (2) : { Block-B; break; } default : { Block-C; } } |
int h = n; if (h == 1) { Block-A; } else { if (h == 2) { Block-B; } else { Block-C; } } |
Beachte: break
aus historischen Gründen (C) nötig
Vorteile: übersichtlicher und effizienter (Sprungtabellen)
Übung: wieso wird rechts neue Variable benutzt?