“Caso de interruptor” Respostas de código

Caixa de interruptor JS

switch(expression) {
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
}
Grotesque Grebe

Declaração de Javascript Declaração vários casos

//javascript multiple case switch statement
var color = "yellow";
var darkOrLight="";
switch(color) {
    case "yellow":case "pink":case "orange":
        darkOrLight = "Light";
        break;
    case "blue":case "purple":case "brown":
        darkOrLight = "Dark";
        break;
    default:
        darkOrLight = "Unknown";
}

//darkOrLight="Light"
Grepper

Switch JS

switch (expr) {
  case 'Oranges':
    console.log('Oranges are $0.59 a pound.');
    break;
  case 'Apples':
    console.log('Apples are $0.32 a pound.');
    break;
  case 'Bananas':
    console.log('Bananas are $0.48 a pound.');
    break;
  case 'Cherries':
    console.log('Cherries are $3.00 a pound.');
    break;
  case 'Mangoes':
  case 'Papayas':
    console.log('Mangoes and papayas are $2.79 a pound.');
    break;
  default:
    console.log('Sorry, we are out of ' + expr + '.');
}

console.log("Is there anything else you'd like?");
Yucky Yak

Caso Siwtch JavaScript

const expr = 'Papayas';
switch (expr) {
  case 'Oranges':
    console.log('Oranges are $0.59 a pound.');
    break;
  case 'Mangoes':
  case 'Papayas':
    console.log('Mangoes and papayas are $2.79 a pound.');
    // expected output: "Mangoes and papayas are $2.79 a pound."
    break;
  default:
    console.log(`Sorry, we are out of ${expr}.`);
}
Tarik

Caso de interruptor

switch (expression) {
  case value1:
    // Anweisungen werden ausgeführt,
    // falls expression mit value1 übereinstimmt
    break;
  case value2:
    // Anweisungen werden ausgeführt,
    // falls expression mit value2 übereinstimmt
    break;
  ...
  case valueN:
    // Anweisungen werden ausgeführt,
    // falls expression mit valueN übereinstimmt
    break;
  default:
    // Anweisungen werden ausgeführt,
    // falls keine der case-Klauseln mit expression übereinstimmt
    break;
}
digimax

Caso de interruptor

char grade = 'B';
switch(grade) {
  case 'A' :
    printf("Excellent!\n" );
    break;...
Aishi Mukherjee

Respostas semelhantes a “Caso de interruptor”

Perguntas semelhantes a “Caso de interruptor”

Mais respostas relacionadas para “Caso de interruptor” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código