¿Hay alguna manera de hacer
switch (expr) { case space or tab: print 'one of em + ' case space: print 'space' case tab: print 'tab' }| Aporte | Producción |
|---|---|
| pestaña | uno de ellos + pestaña |
| espacio | uno de em + espacio |
si no, cuales son las alternativas? Sé que podría usar if else pero como solo estoy usando una expresión como entrada, switch parece más apropiado
No puedes hacer esto con un switch .
Pero if es realmente simple y legible:
if (expr == space || expr == tab) print 'one of em + ' if (expr == space) print 'space' else if (expr == tab) print 'tab'o mejor:
if (expr == space || expr == tab) { print 'one of em + ' if (expr == space) print 'space' else if (expr == tab) print 'tab' }o mejor:
if (expr == space || expr == tab) { print 'one of em + ' if (expr == space) print 'space' else // if (expr == tab) is not needed because print 'tab' // tab is the only possible outcome here. }Todo el código anterior es pseudocódigo.