Difference between revisions of "Basic Pascal Tutorial/Chapter 1/Assignment and Operations/es"

From Free Pascal wiki
Jump to navigationJump to search
Line 1: Line 1:
1E - Asignaciones y operaciones (author: Tao Yue, state: unchanged)
+
[[category:Español]][[category:Castellano]]
 +
1E - Asignaciones y operaciones (autor: Tao Yue, state: ''cambiado'')
  
Una vez declaras una variable, tu puedes almacenar valores en este. Esto es llamado asignación.
+
   Una vez declaramos una variable, podemos almacenar valores en ella. A esto lo llamamos asignación.
Para asignar un valor a una variable, sigue la siguiente sintaxis:
 
<syntaxhighlight>
 
variable_name := expression;
 
</syntaxhighlight>
 
Note que a diferencia de otros lenguajes, su operador de asignacion es exactamente un signo igual, pero Pascal usa dos puntos siguientes seguido del signo igual, de manera similar como se hace en muchos sistemas de álgebra computacional.
 
  
La expresion puede ser un valor simple:
+
&nbsp;&nbsp;&nbsp;Para asignar un valor a una variable, se sigue la siguiente sintaxis:
<syntaxhighlight>
+
 
some_real := 385.385837;
+
<syntaxhighlight> variable_name := expresión;</syntaxhighlight>
</syntaxhighlight>
+
 
o puede ser una secuencia aritmetica:  
+
&nbsp;&nbsp;&nbsp;Resaltar que a diferencia de otros lenguajes, en los que el operador de asignacion es exactamente un signo igual, Pascal usa dos puntos seguidos del signo igual, de manera similar a como se hace en muchos sistemas de álgebra computacional.
<syntaxhighlight>
+
 
some_real := 37573.5 * 37593 + 385.8 / 367.1;
+
&nbsp;&nbsp;&nbsp;La expresion puede ser un valor simple:
</syntaxhighlight>
+
 
Los operadores aritmeticos en Pascal som:
+
<syntaxhighlight> un_numero_real := 385.385837;</syntaxhighlight>
 +
 
 +
&nbsp;&nbsp;&nbsp;o puede ser una expresión aritmetica:  
 +
 
 +
<syntaxhighlight> un_numero_real := 37573.5 * 37593 + 385.8 / 367.1;</syntaxhighlight>
 +
 
 +
&nbsp;&nbsp;&nbsp;Los operadores aritmeticos en Pascal son:
 
{| style="background-color:#f5f5f5" cellspacing=5
 
{| style="background-color:#f5f5f5" cellspacing=5
 
!Operador !!Operación !!Operandos !!Resultado
 
!Operador !!Operación !!Operandos !!Resultado
Line 32: Line 34:
 
|mod ||Modulo (residuo de una división) ||integer ||integer
 
|mod ||Modulo (residuo de una división) ||integer ||integer
 
|}
 
|}
'''<tt>div</tt>''' y'''<tt>mod</tt>''' sólo trabaja con ''integers''. '''<tt>/</tt>''' trabaja con ambos ''reals'' y ''integers'' pero siempre se obtienne un ''real''. Las otras operaciones trabajan sobre ambos ''reals'' y ''integers''. Cuando se mezclan ''integers'' y ''reals'', el resultado siempre será un ''real'' de otro modo se obtendría una perdida de datos. Esa es la razón del porqué Pascal usa dos diferentes operaciones para la division. Es decir <tt>7 / 2 = 3.5</tt> (real), pero <tt>7 div 2 = 3</tt> (y <tt>7 mod 2 = 1</tt> ya que es el residuo).
+
&nbsp;&nbsp;&nbsp;'''<tt>div</tt>''' y '''<tt>mod</tt>''' sólo trabajan con números enteros (''integer''). '''<tt>/</tt>''' trabaja con números reales y enteros pero siempre se obtiene un real. Las otras operaciones trabajan sobre ambos tipos. Cuando se mezclan enteros y reales, el resultado siempre será un número real, de otro modo habría perdida de datos. Esa es la razón de porqué Pascal usa dos diferentes operaciones para la division. Es decir <tt>7 / 2 = 3.5</tt> (real), pero <tt>7 div 2 = 3</tt> (y <tt>7 mod 2 = 1</tt> ya que es el residuo).
 +
 
 +
&nbsp;&nbsp;&nbsp;A cada variable sólo se le puede asignar un valor que es del mismo tipo de dato. Por lo tanto, no se puede asignar un valor real una variable de tipo integer. Sin embargo, ciertos tipos de datos se pueden convertir a otro tipo de dato. Esto sucede cuando se asigna valores de tipo entero a variables de tipo real. Suponga que tiene esta sección de declaración de variables:
 +
 
 +
<syntaxhighlight> var
 +
  un_entero : integer;
 +
  un_real : real;</syntaxhighlight>
 +
 
 +
&nbsp;&nbsp;&nbsp;Cuando el siguiente bloque de instrucciones se ejecuta,
 +
 
 +
<syntaxhighlight>  some_int := 375;
 +
un_real := un_entero;</syntaxhighlight>
 +
 
 +
&nbsp;&nbsp;&nbsp;<tt>un_real</tt> tiene el valor <tt>375.0</tt>.
  
A cada variable sólo se le puede asignar un valor que es del mismo tipo de dato. Por lo tanto, no puedes asignar un valor real una variable de tipo integer. Sin embargo, ciertos tipos de datos se pueden convertir a otro tipo de dato. Esto sucede cuando se asigna valores de tipo integer a variables de tipo real. Suponga que tiene esta sección de declaración de variables:
+
&nbsp;&nbsp;&nbsp;Changing one data type to another is referred to as typecasting. Modern Pascal compilers support explicit typecasting in the manner of C, with a slightly different syntax. However, typecasting is usually used in low-level situations and in connection with object-oriented programming, and a beginning programming student will not need to use it. Here is information on typecasting from the GNU Pascal manual.
  
<syntaxhighlight>
+
&nbsp;&nbsp;&nbsp;In Pascal, the minus sign can be used to make a value negative. The plus sign can also be used to make a value positive, but is typically left out since values default to positive.
var
 
  some_int : integer;
 
  some_real : real;
 
</syntaxhighlight>
 
Cuando el siguiente bloque de instrucciones se ejecuta,
 
<syntaxhighlight>
 
some_int := 375;
 
some_real := some_int;
 
</syntaxhighlight>
 
<tt>some_real</tt> tiene el valor <tt>375.0</tt>.
 
  
Changing one data type to another is referred to as typecasting. Modern Pascal compilers support explicit typecasting in the manner of C, with a slightly different syntax. However, typecasting is usually used in low-level situations and in connection with object-oriented programming, and a beginning programming student will not need to use it. Here is information on typecasting from the GNU Pascal manual.
+
&nbsp;&nbsp;&nbsp;Do not attempt to use two operators side by side, like in:
  
In Pascal, the minus sign can be used to make a value negative. The plus sign can also be used to make a value positive, but is typically left out since values default to positive.
+
<syntaxhighlight> un_real := 37.5 * -2;</syntaxhighlight>
  
Do not attempt to use two operators side by side, like in:
+
&nbsp;&nbsp;&nbsp;This may make perfect sense to you, since you're trying to multiply by negative-2. However, Pascal will be confused — it won't know whether to multiply or subtract. You can avoid this by using parentheses to clarify:
<syntaxhighlight>
 
some_real := 37.5 * -2;
 
</syntaxhighlight>
 
  
This may make perfect sense to you, since you're trying to multiply by negative-2. However, Pascal will be confused — it won't know whether to multiply or subtract. You can avoid this by using parentheses to clarify:
+
<syntaxhighlight> un_real := 37.5 * (-2);</syntaxhighlight>
<syntaxhighlight>
 
some_real := 37.5 * (-2);
 
</syntaxhighlight>
 
  
The computer follows an order of operations similar to the one that you follow when you do arithmetic. Multiplication and division (<tt>* / div mod</tt>) come before addition and subtraction (<tt>+ -</tt>), and parentheses always take precedence. So, for example, the value of: <tt>3.5*(2+3)</tt> will be <tt>17.5.</tt>
+
&nbsp;&nbsp;&nbsp;The computer follows an order of operations similar to the one that you follow when you do arithmetic. Multiplication and division (<tt>* / div mod</tt>) come before addition and subtraction (<tt>+ -</tt>), and parentheses always take precedence. So, for example, the value of: <tt>3.5*(2+3)</tt> will be <tt>17.5.</tt>
  
Pascal cannot perform standard arithmetic operations on Booleans. There is a special set of Boolean operations. Also, you should not perform arithmetic operations on characters.
+
&nbsp;&nbsp;&nbsp;Pascal cannot perform standard arithmetic operations on Booleans. There is a special set of Boolean operations. Also, you should not perform arithmetic operations on characters.
  
 
{|style=color-backgroud="white" cellspacing="20"
 
{|style=color-backgroud="white" cellspacing="20"
|[[Variables_and_Data_Types|previous]]   
+
|[[Variables_and_Data_Types/es|previo]]   
|[[Contents|contents]]  
+
|[[Contents/es|índice]]  
|[[Standard_Functions|next]]
+
|[[Standard_Functions/es|siguiente]]
 
|}
 
|}

Revision as of 02:24, 11 August 2012

1E - Asignaciones y operaciones (autor: Tao Yue, state: cambiado)

   Una vez declaramos una variable, podemos almacenar valores en ella. A esto lo llamamos asignación.

   Para asignar un valor a una variable, se sigue la siguiente sintaxis:

 variable_name := expresión;

   Resaltar que a diferencia de otros lenguajes, en los que el operador de asignacion es exactamente un signo igual, Pascal usa dos puntos seguidos del signo igual, de manera similar a como se hace en muchos sistemas de álgebra computacional.

   La expresion puede ser un valor simple:

 un_numero_real := 385.385837;

   o puede ser una expresión aritmetica:

 un_numero_real := 37573.5 * 37593 + 385.8 / 367.1;

   Los operadores aritmeticos en Pascal son:

Operador Operación Operandos Resultado
+ Adición o operador unario positivo real o integer real o integer
- Substración o operador unario negativo real o integer real o integer
* Multiplicación real o integer real o integer
/ División real real o integer real
div División con enteros integer integer
mod Modulo (residuo de una división) integer integer

   div y mod sólo trabajan con números enteros (integer). / trabaja con números reales y enteros pero siempre se obtiene un real. Las otras operaciones trabajan sobre ambos tipos. Cuando se mezclan enteros y reales, el resultado siempre será un número real, de otro modo habría perdida de datos. Esa es la razón de porqué Pascal usa dos diferentes operaciones para la division. Es decir 7 / 2 = 3.5 (real), pero 7 div 2 = 3 (y 7 mod 2 = 1 ya que es el residuo).

   A cada variable sólo se le puede asignar un valor que es del mismo tipo de dato. Por lo tanto, no se puede asignar un valor real una variable de tipo integer. Sin embargo, ciertos tipos de datos se pueden convertir a otro tipo de dato. Esto sucede cuando se asigna valores de tipo entero a variables de tipo real. Suponga que tiene esta sección de declaración de variables:

 var
  un_entero : integer;
  un_real : real;

   Cuando el siguiente bloque de instrucciones se ejecuta,

  some_int := 375;
 un_real := un_entero;

   un_real tiene el valor 375.0.

   Changing one data type to another is referred to as typecasting. Modern Pascal compilers support explicit typecasting in the manner of C, with a slightly different syntax. However, typecasting is usually used in low-level situations and in connection with object-oriented programming, and a beginning programming student will not need to use it. Here is information on typecasting from the GNU Pascal manual.

   In Pascal, the minus sign can be used to make a value negative. The plus sign can also be used to make a value positive, but is typically left out since values default to positive.

   Do not attempt to use two operators side by side, like in:

 un_real := 37.5 * -2;

   This may make perfect sense to you, since you're trying to multiply by negative-2. However, Pascal will be confused — it won't know whether to multiply or subtract. You can avoid this by using parentheses to clarify:

 un_real := 37.5 * (-2);

   The computer follows an order of operations similar to the one that you follow when you do arithmetic. Multiplication and division (* / div mod) come before addition and subtraction (+ -), and parentheses always take precedence. So, for example, the value of: 3.5*(2+3) will be 17.5.

   Pascal cannot perform standard arithmetic operations on Booleans. There is a special set of Boolean operations. Also, you should not perform arithmetic operations on characters.

previo índice siguiente