CASE/fr: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Case/fr
| Old | New | Line | |
|---|---|---|---|
| 1 | + | Case débute une instruction case. Cette instruction compare la valeur de l'expression ordinale qui suit le *case* à chaque sélecteur, qui peut être une [[Const/fr|constante]], un intervalle, ou une liste d'eux séparé par des [[Comma/fr|virgules]]. Le champ sélecteur est séparé de l'action par [[Colon/fr|deux-points (:)]]. | |
| 2 | + | ||
| 3 | + | L'instruction case comporte les [[Reserved words/fr|mots réservés]] [[Of/fr|of]] et [[End/fr|end]]. [[Else/fr|else]] peut être utilisée si besoin est. | |
| 4 | + | ||
| 5 | + | ``` pascal | |
| 6 | + | case place of | |
| 7 | + | 1: ShowMessage('Gold medal'); | |
| 8 | + | 2: ShowMessage('Silver medal'); | |
| 9 | + | 3: ShowMessage('Bronze medal'); | |
| 10 | + | else ShowMessage('Better luck next time'); | |
| 11 | + | end; | |
| 12 | + | ``` | |
| 13 | + | ||
| 14 | + | ### Fonction WhatIsChar | |
| 15 | + | ||
| 16 | + | ``` pascal | |
| 17 | + | function WhatIsChar( c:char ):string; | |
| 18 | + | var | |
| 19 | + | s : string; | |
| 20 | + | begin | |
| 21 | + | s := ''; | |
| 22 | + | case c of | |
| 23 | + | '0' .. '9' : s := 'digit (0-9)'; | |
| 24 | + | 'a' .. 'z' : s := 'lowercase letter (a-z)'; | |
| 25 | + | 'A' .. 'Z' : s := 'uppercase letter (A-Z)'; | |
| 26 | + | '+' , '-' : s := 'sign (+ or -)'; | |
| 27 | + | end; | |
| 28 | + | result := s; | |
| 29 | + | end; | |
| 30 | + | ``` | |
| 31 | + | ||
| 32 | + | ## Enregistrement avec variantes | |
| 33 | + | ||
| 34 | + | Case est aussi utilisé dans les [[Record/fr|enregistrements]] avec variantes. | |
| 35 | + | ||
| 36 | + | ``` pascal | |
| 37 | + | type | |
| 38 | + | ||
| 39 | + | ScaleKelvin = 223 .. 323; | |
| 40 | + | ScaleCelsius = -50 .. 50; | |
| 41 | + | ||
| 42 | + | TemperatureScale = ( celsius, kelvin ) ; | |
| 43 | + | Temperature = record | |
| 44 | + | case scale : TemperatureScale of | |
| 45 | + | celsius : (celsius_value : ScaleCelsius); | |
| 46 | + | kelvin : (kelvin_value : ScaleKelvin); | |
| 47 | + | end; | |
| 48 | + | ``` | |
| 49 | + | ||
| 50 | + | ## Voir aussi | |
| 51 | + | ||
| 52 | + | - [The Case statement](http://www.freepascal.org/docs-html/ref/refsu40.html#x110-11700010.2.2) | |
| 53 | + | - [Record types](http://www.freepascal.org/docs-html/ref/refsu15.html#x38-450003.3.2) | |
| 54 | + | - [Tao Yue: Learn Pascal!](http://lazarus-ccr.sourceforge.net/pascal/pas3cb.html) Case | |
| 55 | + | - [Video: Free Pascal Tutorial 8 - Case Statements](http://www.youtube.com/watch?v=pMr2xtUu3x0) | |
| 56 | + | - [[Dialog Examples|ShowMessage]] | |
| 57 | + | - [[Type/fr|Type]] | |
| 58 | + | ||
| 59 | + | --- | |
| 60 | + | *From the Free Pascal wiki, page "Case/fr", as it stood on 2022-08-10 after a change by Kai Burghardt, 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).* | |
| 61 | + | Category: Control Structures/fr | |
| 62 | + | Category: Pascal/fr |
