Hello,
Je dois me faire un switch sur un string. Comme cela n'est évidemment pas possible, on a généralement recours à des if en cascade.
Toutefois, cela n'est guère agréable de consulter un tel code :
Je me demandais si cela n'était pas l'occasion d'utiliser le bon vieux goto :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 if (myString == "toto") doToto(); else { if (myString == "tata") doTata(); else { if (myString == "titi") doTiti(); } }
Ne trouvez-vous pas cela plus propre/lisible ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 if (myString == "toto") { doToto(); goto papam; } if (myString == "tata") { doTata(); goto papam; } if (myString == "titi") { doTiti(); goto papam; } papam : ...
Partager