Objectifs

  1. A quoi sert l’instruction if ?
  2. Les 3 formes de déclaration de l’instruction if…else
  3. Les erreurs à éviter

Syntaxe 1

if cond1

{

  instruction 1;

  instruction 2;

  ...;

}

else

{

  instruction 3;

  instruction 4;

  ...;

}

Syntaxe 2

if cond1

{

  instruction 1;

  instruction 2;

  ...;

}

else if cond2

{

  instruction 3;

  instruction 4;

  ...;

}

else if cond3

{

  instruction 5;

  instruction 6;

  ...;

}

...

else  condn

{

  instruction n-1;

  instruction n;

  ...;

}

Syntaxe 3

if cond

{

  instruction 1;

  instruction 2;

  ...;

}

Les erreurs à éviter

  1. Syntaxe: elseif; elsif; % else if
  2. Logique: Oublie des accolades {}
if cond1

  instruction 1; % Instruction exécutée

  instruction 2; % Instruction non incluses

else

  instruction 1; % Instruction exécutée

  instruction 2; % Instruction non inclus
Click to rate this post!
[Total: 4 Average: 3.8]

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.