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:30] thierry [Avec un tableau] |
prog:theorie:iterations [31/10/2022 17:04] (Version actuelle) thierry [Foreach] |
||
---|---|---|---|
Ligne 74: | 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 125: | Ligne 135: | ||
==== Pascal ==== | ==== Pascal ==== | ||
=== Break === | === 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 === | ||
- | === Goto === | + | ''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> | ||