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]].
  
The case statement includes [[Reserved word|reserved words]] [[Of]] and [[End]] . Sometimes [[Else]], too.
+
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('Gold medal');
+
   1: ShowMessage('Medalla de oro');
   2: ShowMessage('Silver medal');
+
   2: ShowMessage('Medalla de plata');
   3: ShowMessage('Bronze medal');  
+
   3: ShowMessage('Medalla de bronce');  
   else ShowMessage('Better luck next time');  
+
   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 := 'digit (0-9)';
+
     '0' .. '9' : s := 'digito (0-9)';
     'a' .. 'z' : s := 'small letter (a-z)';
+
     'a' .. 'z' : s := 'letras minúsculas(a-z)';
     'A' .. 'Z' : s := 'big letter (A-Z)';
+
     'A' .. 'Z' : s := 'letras mayúsculas (A-Z)';
     '+' , '-'  : s := 'sign (+ or -)';
+
     '+' , '-'  : s := 'signo (+ o -)';
 
   end;
 
   end;
 
   result := s;
 
   result := s;
Line 45: Line 45:
 
   type
 
   type
 
        
 
        
   ScaleKelvin = 223 .. 323;
+
   Escala_Kelvin = 223 .. 323;
   ScaleCelsius = -50 .. 50;
+
   Escala_Celsius = -50 .. 50;
 
      
 
      
   TemperatureScale   =  ( celcius, kelvin ) ;
+
   Escala_Temperatura   =  ( celcius, kelvin ) ;
   Temperature   =  record
+
   Temperatura   =  record
     case  scale   :  TemperatureScale   of
+
     case  escala   :  Escala_Temperatura   of
     celcius : (celcius_value : ScaleCelsius);
+
     celsius : (valor_celcius : Escala_Celsius);
     kelvin : (kelvin_value : ScaleKelvin);
+
     kelvin : (valor_kelvin : Escala_Kelvin);
 
   end;
 
   end;
  
 
</delphi>
 
</delphi>
  
== Read more ==
+
== 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>

Leer más