Objectifs

  1. A quoi sert la structure switch .. case ?
  2. La syntaxe
  3. Les erreurs à éviter

Syntaxe

switch var

{

  case val1 % Cas 1

    inst1;

    ...;

    break;




  case val2 % Cas 2

    inst2;

    ...;

    break;




  case val3 % Cas 3

    inst3;

    ...;

    break;




  case valn % Cas n

    ...;




  default % Cas par défaut

    inst1;

    ...;

}

Les erreurs à éviter

  1. Oublie de l’instruction break
switch var

{

  case val1 % Cas 1

    inst1;

    ...; 

  case val2  % Cas 2

    inst2;

    ...;  

  default   % Cas par défaut

    inst3;

    ...;

}
Click to rate this post!
[Total: 0 Average: 0]

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Retour en haut

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

FPGA | Arduino | Matlab | Cours will use the information you provide on this form to be in touch with you and to provide updates and marketing.