Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
Two exclusive conditions along with one or condition for two values in switch statement

Is there a way to do

switch (expr) {
case space or tab:
print 'one of em + '
case space:
print 'space'
case tab:
print 'tab'
}
Input Output
tab one of em + tab
space one of em + space

If not, what are the alternatives? I know I could use if else but since I'm only using one expression as input, switch seems more appropriate

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You cannot do this with a switch.

But with if it's really simple and readable:

if (expr == space || expr == tab)
  print 'one of em + '
if (expr == space)
  print 'space'
else if (expr == tab)
  print 'tab'

or better:

if (expr == space || expr == tab)
{
  print 'one of em + '
  if (expr == space)
    print 'space'
  else if (expr == tab)
    print 'tab'
}

or even better:

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.
}

All code above is pseudo code.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda