Difference between revisions of "Case/es"
From Free Pascal wiki
Jump to navigationJump to search (New page: {{Case}} Case opens a case statement. The case statement compares the value of ordinal expression to each selector, which can be a constant, a subrange, or a list of them separa...) |
|||
Line 3: | Line 3: | ||
Case opens a case statement. The case statement compares the value of ordinal expression to each selector, which can be a [[Const|constant]], a subrange, or a list of them separated by [[Comma|commas]]. Selector field separated from action field by [[Colon]]. | Case opens a case statement. The case statement compares the value of ordinal expression to each selector, which can be a [[Const|constant]], a subrange, or a list of them separated by [[Comma|commas]]. Selector field separated from action field by [[Colon]]. | ||
− | + | La sentencia "case" incluye [[Reserved word | las palabras reservadas]] [[Of]] y [[End]] . algunas veces [[Else]], también. | |
Line 9: | Line 9: | ||
case place of | case place of | ||
− | 1: ShowMessage(' | + | 1: ShowMessage('Medalla de oro'); |
− | 2: ShowMessage(' | + | 2: ShowMessage('Medalla de plata'); |
− | 3: ShowMessage(' | + | 3: ShowMessage('Medalla de bronce'); |
− | else ShowMessage(' | + | else ShowMessage('Mejor suerte la siguiente vez'); |
end; | end; | ||
Line 21: | Line 21: | ||
<delphi> | <delphi> | ||
− | function WhatIsChar( c:char ):string; | + | function WhatIsChar( c:char ):string; { recibe un parámetro "char" y retorna un string } |
var | var | ||
s : string; | s : string; | ||
Line 27: | Line 27: | ||
s := ''; | s := ''; | ||
case c of | case c of | ||
− | '0' .. '9' : s := ' | + | '0' .. '9' : s := 'digito (0-9)'; |
− | 'a' .. 'z' : s := ' | + | 'a' .. 'z' : s := 'letras minúsculas(a-z)'; |
− | 'A' .. 'Z' : s := ' | + | 'A' .. 'Z' : s := 'letras mayúsculas (A-Z)'; |
− | '+' , '-' : s := ' | + | '+' , '-' : s := 'signo (+ o -)'; |
end; | end; | ||
result := s; | result := s; | ||
Line 45: | Line 45: | ||
type | type | ||
− | + | Escala_Kelvin = 223 .. 323; | |
− | + | Escala_Celsius = -50 .. 50; | |
− | + | Escala_Temperatura = ( celcius, kelvin ) ; | |
− | + | Temperatura = record | |
− | case | + | case escala : Escala_Temperatura of |
− | + | celsius : (valor_celcius : Escala_Celsius); | |
− | kelvin : ( | + | kelvin : (valor_kelvin : Escala_Kelvin); |
end; | end; | ||
</delphi> | </delphi> | ||
− | == | + | == Leer más == |
* [http://www.freepascal.org/docs-html/ref/refsu40.html#x110-11700010.2.2 The Case statement] | * [http://www.freepascal.org/docs-html/ref/refsu40.html#x110-11700010.2.2 The Case statement] |
Revision as of 01:05, 24 November 2009
│
Deutsch (de) │
English (en) │
español (es) │
suomi (fi) │
français (fr) │
русский (ru) │
Case opens a case statement. The case statement compares the value of ordinal expression to each selector, which can be a constant, a subrange, or a list of them separated by commas. Selector field separated from action field by Colon.
La sentencia "case" incluye las palabras reservadas Of y End . algunas veces Else, también.
<delphi>
case place of 1: ShowMessage('Medalla de oro'); 2: ShowMessage('Medalla de plata'); 3: ShowMessage('Medalla de bronce'); else ShowMessage('Mejor suerte la siguiente vez'); end;
</delphi>
WhatIsChar
<delphi>
function WhatIsChar( c:char ):string; { recibe un parámetro "char" y retorna un string } var s : string; begin s := ; case c of '0' .. '9' : s := 'digito (0-9)'; 'a' .. 'z' : s := 'letras minúsculas(a-z)'; 'A' .. 'Z' : s := 'letras mayúsculas (A-Z)'; '+' , '-' : s := 'signo (+ o -)'; end; result := s; end;
</delphi>
Variant Record
Case-word is used Variant Record, too. Variant Record also called a tagged union.
<delphi>
type Escala_Kelvin = 223 .. 323; Escala_Celsius = -50 .. 50; Escala_Temperatura = ( celcius, kelvin ) ; Temperatura = record case escala : Escala_Temperatura of celsius : (valor_celcius : Escala_Celsius); kelvin : (valor_kelvin : Escala_Kelvin); end;
</delphi>