Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
|
prog:theorie:iterations [09/10/2022 15:25] thierry [Pascal] |
prog:theorie:iterations [31/10/2022 17:04] (Version actuelle) thierry [Foreach] |
||
|---|---|---|---|
| Ligne 39: | Ligne 39: | ||
| end; | end; | ||
| </code> | </code> | ||
| + | === Repeat Until === | ||
| + | <code delphi Pascal> | ||
| + | a := 10; | ||
| + | repeat | ||
| + | writeln('value of a: ', a); | ||
| + | a := a + 1 | ||
| + | until a = 20; | ||
| + | </code> | ||
| + | |||
| ===== For...To ===== | ===== For...To ===== | ||
| Ligne 65: | Ligne 74: | ||
| </code> | </code> | ||
| - | ===== For...In ===== | + | ===== Foreach ===== |
| + | Equivalents ''for...of'' ou ''for..in''' en javascript | ||
| + | ==== PHP ==== | ||
| + | <code php php> | ||
| + | foreach ($tickets as $ticket) { | ||
| + | ... | ||
| + | } | ||
| + | </code> | ||
| + | |||
| + | |||
| + | ===== For...In===== | ||
| ==== Javascript ==== | ==== Javascript ==== | ||
| === Avec un tableau === | === Avec un tableau === | ||
| Ligne 112: | Ligne 131: | ||
| Banane | Banane | ||
| </code> | </code> | ||
| + | |||
| + | ===== Contrôles des boucles ===== | ||
| + | ==== Pascal ==== | ||
| + | === Break === | ||
| + | ''break'' sort de la boucle | ||
| + | <code delphi Code> | ||
| + | a := 10; | ||
| + | while a < 20 do | ||
| + | |||
| + | begin | ||
| + | writeln('value of a: ', a); | ||
| + | a:=a +1; | ||
| + | if( a > 15) then break; | ||
| + | end; | ||
| + | </code> | ||
| + | <code c Résultat> | ||
| + | value of a: 10 | ||
| + | value of a: 11 | ||
| + | value of a: 12 | ||
| + | value of a: 13 | ||
| + | value of a: 14 | ||
| + | value of a: 15 | ||
| + | |||
| + | </code> | ||
| + | === Continue === | ||
| + | ''continue'' retourne au début de la boucle : | ||
| + | <code delphi Code> | ||
| + | a := 10; | ||
| + | repeat | ||
| + | if( a = 15) then | ||
| + | begin | ||
| + | a := a + 1; | ||
| + | continue; | ||
| + | end; | ||
| + | writeln('value of a: ', a); | ||
| + | a := a+1; | ||
| + | until ( a = 20 ); | ||
| + | </code> | ||
| + | <code c Résultat> | ||
| + | value of a: 10 | ||
| + | value of a: 11 | ||
| + | value of a: 12 | ||
| + | value of a: 13 | ||
| + | value of a: 14 | ||
| + | value of a: 16 | ||
| + | value of a: 17 | ||
| + | value of a: 18 | ||
| + | value of a: 19 | ||
| + | |||
| + | </code> | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||