Test | Si ... | Si ... sinon ... | Si avec plusieurs cas |
---|---|---|---|
Au bac |
Si x = 5 Alors action
ou
Si x = 5 Alors
actions
ou
Si x = 5 Alors
actions
Fin si
ou d'autres variantes.
|
Si x = 5 Alors
actions
Sinon
actions
Fin si
ou variantes.
|
Si x < 0 Alors
actions
Sinon, si x < 1 Alors
actions
Sinon
actions
Fin si
ou variantes (jamais vu dans un sujet de bac, mais ça pourrait prendre ce genre de forme).
|
Algobox |
SI (x == 5) ALORS
DEBUT_SI
action(s)
FIN_SI
|
SI (x == 5) ALORS
DEBUT_SI
action(s)
FIN_SI
SINON
DEBUT_SINON
action(s)
FIN_SINON
|
SI (x < 0) ALORS
DEBUT_SI
action(s)
FIN_SI
SINON
DEBUT_SINON
SI (x < 1) ALORS
DEBUT_SI
action(s)
FIN_SI
SINON
DEBUT_SINON
action(s)
FIN_SINON
FIN_SINON
dans certains cas on peut aussi utiliser la fonction F2. |
Javascript |
if (x == 5) action;
ou
if (x == 5) {
actions;
}
|
if (x == 5) {
actions;
}
else {
actions;
}
|
if (x < 0) {
actions;
}
else if (x < 1) {
actions;
}
else {
actions;
}
|
Python |
if x == 5:
action(s)
|
if x == 5:
action(s)
else:
action(s)
|
if x < 0:
action(s)
elif x < 1:
action(s)
else:
action(s)
|
R |
if (x == 5) action;
ou
if (x == 5) {
actions;
}
|
if (x == 5) {
actions;
}
else {
actions;
}
|
if (x < 0) {
actions;
}
else if (x < 1) {
actions;
}
else {
actions;
}
|
Casio |
If X=5↲
Then actions↲ IfEnd↲ |
X=5⇒action↲
ou
action↲ If X=5↲
Then action(s)↲ Else action(s)↲ IfEnd↲ |
X<0⇒action↲
ou
X<1⇒action↲ action↲ If X<0↲
Then action(s)↲ Else If X<1↲ Then action(s)↲ Else action(s)↲ IfEnd↲ IfEnd↲ |
TI-Basic |
:If X=5
ou
:action :If X=5
:Then :actions :End |
:If X=5
:Then :actions :Else :actions :End |
:If X<0
:Then :actions :Else ::If X<1 ::Then ::actions ::Else ::actions ::End :End |
Xcas |
si x == 5 alors action fsi
ou
si x == 5 alors
actions;
fsi;
|
si x == 5 alors
actions;
sinon
actions;
fsi;
|
si x < 0 alors
actions;
sinon
si x < 1 alors
actions;
sinon
actions;
fsi;
fsi;
|
XLogo |
si x = 5 action
ou
si x = 5 [actions]
|
si x = 5 [actions]
ou
[actions] sisinon x = 5 [actions]
[actions] |
si x < 0 [actions]
si x < 1 [actions]
[actions]
|
Comparaison | strictement égal | égal au sens « large »1 | strictement différent | différent au sens « large »1 | inférieur2, 3 | inférieur ou égal2, 3 | supérieur2, 3 | supérieur ou égal2, 3 | et | ou4 | non logique, comme dans "non(a=b)" qui est équivalent à "a≠b" |
Algobox | === | == | !== | != |
< | <= | > | >= |
ET | OU | !a==b |
Javascript | === | == | !== | != |
< | <= | > | >= |
&& | || | !a==b |
Python | == | != | < | <= | > | >= |
and | or | not a==b |
||
R | == | != |
< | <= | > | >= |
&& | || | !a==b |
||
Casio | = | ≠ | < | ≤ | > | ≥ |
And | Or | Not A=B |
||
TI-Basic | = | ≠ | < | ≤ | > | ≥ |
and | or | not(A=B) |
||
XCas | == | != | < | <= | > | >= |
et | ou | non(a==b) |
||
XLogo | = | non(a=b) | < | <= | > | >= |
et | ou | non(a=b) |
Au bac |
Répéter 10 fois action
ou
Pour i variant de 0 à 9
ou
actions Répéter 10 fois
ou variantes
actions Fin répéter |
Tant que i < 10, répéter action
ou
Tant que i < 10
ou variantes.
actions Fin Tant que |
Algobox |
POUR i ALLANT_DE 0 A 9
DEBUT_POUR
action(s)
FIN_POUR
|
TANT_QUE (i < 10) FAIRE
DEBUT_TANT_QUE
action(s)
FIN_TANT_QUE
|
Javascript |
for (i = 0; i < 10; i++) action;
ou
for (i = 0; i < 10; i++) {
action(s);
}
|
while (i < 10) { action(s); } |
Python | for i in range(10): action(s) |
while i < 10: action(s) |
R |
for (i in 0:9) action
ou
for (i in 0:9) {
actions;
}
|
while (i < 10) { action(s); } |
Casio | For 0→I To 9↲ action(s)↲ Next↲ |
While I<10↲ action(s)↲ WhileEnd↲ |
TI-Basic | :For(I,0,9) :action(s) :End |
:While I<10 :action(s) :End |
XCas |
pour k de 1 jusque 10 faire
action(s)
fpour;
|
tantque k < 10 faire
action(s)
ftantque;
|
XLogo | repete 10 [action(s)] |
tantque [i < 10] [action(s)] |
<
ou <=
permet de choisir.
Cependant parfois il vaut mieux éviter d'inclure la borne de fin avec <=
à cause des erreurs d'arrondis et de représentation des nombres.Au bac | Pour x allant de −6.2 à 6.21, de 0.8 en 0.8 | Répéter action jusqu'à2, 3 ce que i = 10 |
Algobox |
x PREND_LA_VALEUR -6.2
TANT_QUE (x < 6.2) FAIRE
DEBUT_TANT_QUE
action(s)
x PREND_LA_VALEUR x+0.8
FIN_TANT_QUE
|
si on est absolument sûr que i≠10 avant le début de la boucle3 :
TANT_QUE (i != 10) FAIRE
DEBUT_TANT_QUE
action(s)
FIN_TANT_QUE
|
Javascript |
for (x = -6.2; x < 6.2; x += 0.8) {
action(s);
}
|
do { action(s); } while (i != 10) |
Python |
x = -6.2
while x < 6.2:
action(s)
x = x + 0.8
|
while True:
ou, si on est absolument sûr que i≠10 avant le début de la boucle3 :
action(s) if i == 10: break while i != 10:
action(s) |
R |
-6.2->x;
while (x < 6.2) {
action(s);
x+0.8->x;
}
|
repeat { action(s); if (i == 10) break; } |
Casio | For -6.2→X To 6.2 Step 0.8↲ action(s)↲ Next↲ |
Do↲ action(s)↲ LpWhile I≠10↲ |
TI-Basic | :For(X,-6.2,6.2,0.8) :action(s) :End |
:Repeat I=10 :action(s) :End |
XCas |
pour x de -6.2 jusque 6.2 pas 0.8 faire
s:=s+0.8;
fpour;
|
repeter
action(s)
jusqua i == 10;
|
XLogo | repetepour [i -6.2 6.2 0.8] [action(s)] |
repetejusqua [i == 10] [action(s)] |
Répéter ... jusqu'à ...
n'existe pas. On la trouve en TI-basic, XCas et XLogo, aussi en R sous une forme particulière (repeat ... break
).Répéter ... tant que ...
avec la condition contraire. Il existe aussi des instructions
de fin de boucle anticipée (souvent break
) qui ont le même effet que jusqu'à
.Répéter ... jusqu'à ...
s'exécute toujours au moins une fois, même si la condition d'arrêt est réalisée avant de commencer, car le test n'est effectué quà la fin de la première itération.