Académique Documents
Professionnel Documents
Culture Documents
A. ARESMOUK
SOMMAIRE
2
LES STRUCTURES DE CONTRÔLE
LA BOUCLE « FOR »
L’instruction « for » permet de répéter un bloc d’instructions, un
nombre déterminé de fois.
La syntaxe est de la forme:
3
LES STRUCTURES DE CONTRÔLE
Exemple 1:
4
LES STRUCTURES DE CONTRÔLE
LA BOUCLE « FOR »
Exemple 2:
clear all
for i = 1:3
for j = 1:4
M(i, j) = i + j;
end
end
disp(M)
5
LES STRUCTURES DE CONTRÔLE
LA BOUCLE « FOR »
Exemple 2:
6
LES STRUCTURES DE CONTRÔLE
LA BOUCLE « WHILE »
La syntaxe est de la forme:
while (relation)
Séquence d’instructions
end
7
LES STRUCTURES DE CONTRÔLE
LA BOUCLE « WHILE »
Exemple 1:
8
LES STRUCTURES DE CONTRÔLE
L’instruction « BREAK »
L’instruction « break » permet de sortir d’une boucle « for » ou
« while ».
Exemple
clear all
for i = -2:2:10
if(i==4)
break
end
disp(i)
end
9
LES STRUCTURES DE CONTRÔLE
L’instruction « BREAK »
L’instruction « break » permet de sortir d’une boucle « for » ou
« while ».
Exemple
clear all >> Exemple
for i = -2:2:10 -2
if(i==6) 0
break 2
end 4
disp(i)
end
10