Sign in Join
Wiki copytemporary

For/fr: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11[[Keyword/fr|keyword]] utilisé avec "[[To/fr|to]]" ou "[[Downto/fr|downto]]" et "[[Do/fr|do]]" pour parcourir une boucle dans laquelle la variable de contrôle est incrémentée ou décrémentée de 1 à chaque fois :
22
3-`FOR `*`control_variable`*` := `*`start`*` `[[To/fr|TO]]` `*`final`*` DO `*`statement`*
3+``` pascal
4+FOR control_variable := start TO final DO statement
5+```
46
57qui augmente *control_variable* de 1 à chaque exécution de la boucle jusqu'à ce que la valeur soit supérieure ou égale à *final* ou
68
7-`FOR `*`control_variable`*` := `*`start`*` `[[Downto/fr|DOWNTO]]` `*`final`*` do `*`statement`*
9+``` pascal
10+FOR control_variable := start DOWNTO final do statement
11+```
812
913qui diminue *control_variable* de 1 à chaque exécution de la boucle jusqu'à ce que la valeur soit inférieure ou égale à *final*
1014
1115où *control_variable* Where *control_variable* est la variable mise à la valeur *start* au départ.
1216
1317``` pascal
1418For I:=1 To 100 Do statement;
1519```
1620
1721(répète *statement* 100 fois, en augmentant I de 1 à 100)
1822
1923``` pascal
2024 for I:=100 downto 1 do ''statement'';
2125```
2226
2327(répète *statement* 100 fois, en diminuant I de 100 à 1)
2428
2529- FOR bouclera l'unique instruction qui le suit. Pour exécute plus d'une instruction, il faut entourer la séquence d'instructions avec un bloc [[Begin/fr|Begin]]/[[End/fr|End]].
2630- Dans une boucle for..to, si *start* est supérieur à *final*, la boucle n'est pas exécutée.
2731- Dans une boucle for..downto, si *start* is inférieur à *final*, la boucle n'est pas exécutée.
2832
2933After the loop, the value of *control_variable* will be *final*. If the loop was not executed, the value of *control_variable* does not change.
3034
3135## Variables enumérées
3236
3337[[Pascal/fr|Pascal]] permet d'employer une variable de contrôle d'un type énuméré (par exemple un booléen) au lieu d'un variable entière :
3438
3539``` pascal
3640program Fruits;
3741type
3842 TFruit = (fPomme, fPoire, fFraise, fMirabelle, fPrune, fFramboise, fCassis);
3943const
4044 FruitTextes: array[TFruit] of String =
4145 ('Pomme', 'Poire', 'Fraise', 'Mirabelle', 'Prune', 'Framboise', 'Cassis');
4246begin
4347 WriteLn('** Liste des fruits **');
4448 for f := Low(TFruit) to High(TFruit) do
4549 WriteLn(FruitTextes[f]);
4650End;
4751
4852End.
4953```
5054
5155## Extension de Pascal Objet
5256
5357- [[for-in loop/fr|Boucle for...in]]
5458
5559L'exemple des fruits devient :
5660
5761``` pascal
5862program Fruits;
5963type
6064 TFruit = (fPomme, fPoire, fFraise, fMirabelle, fPrune, fFramboise, fCassis);
6165const
6266 FruitTextes: array[TFruit] of String =
6367 ('Pomme', 'Poire', 'Fraise', 'Mirabelle', 'Prune', 'Framboise', 'Cassis');
6468begin
6569 WriteLn('** Liste des fruits **');
6670 for f in TFruit do
6771 WriteLn(FruitTextes[f]);
6872End;
6973
7074End.
7175```
7276
7377Ce qui est plus joli, non ?
7478
7579## Voir aussi
7680
7781- [[Example: Why the loop variable should be of signed type]]
7882
7983---
8084*From the Free Pascal wiki, page "For/fr", as it stood on 2020-02-15 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history