Difference between revisions of "Basic Pascal Tutorial/Chapter 1/Program Structure/es"

From Lazarus wiki
Jump to navigationJump to search
(New page: Bases 1A - Estructura de un Programa (author: Tao Yue, state: unchanged)    La estructura básica de un programa Pascal es: <delphi> PROGRAM NombrePrograma (ListaArchivos);...)
 
Line 7: Line 7:
 
  CONST
 
  CONST
 
   (* Declaración de Constantes *)
 
   (* Declaración de Constantes *)
 
 
  TYPE
 
  TYPE
 
   (* Declaración de Tipos *)
 
   (* Declaración de Tipos *)
 
 
  VAR
 
  VAR
 
   (* Declaración de Variables *)
 
   (* Declaración de Variables *)
 
 
  (* Definiciones de Subprogramas *)
 
  (* Definiciones de Subprogramas *)
 
 
  BEGIN
 
  BEGIN
 
   (* Sentencias ejecutables *)
 
   (* Sentencias ejecutables *)
 
  END.</delphi>
 
  END.</delphi>
 
&nbsp;&nbsp;&nbsp;Los elementos del programa deben aparecer en el orden correcto, aunque pueden ser omitidos si no se necesitan.
 
&nbsp;&nbsp;&nbsp;Los elementos del programa deben aparecer en el orden correcto, aunque pueden ser omitidos si no se necesitan.
&nbsp;&nbsp;&nbsp;  
+
 
Aquí hay un programa que no hace nada, pero tiene todos los elementos necesarios:
+
&nbsp;&nbsp;&nbsp;Aquí hay un programa que no hace nada, pero tiene todos los elementos necesarios:
 
<delphi> program HacerNada;
 
<delphi> program HacerNada;
 
  begin
 
  begin
 
  end.</delphi>
 
  end.</delphi>
Los comentarios son partes del código que no se compilan ni ejecutan. Los comentarios en Pascal comienzan con (* y terminan con *). No se puede anidar comentarios.  
+
&nbsp;&nbsp;&nbsp;Los comentarios son partes del código que no se compilan ni ejecutan. Los comentarios en Pascal comienzan con (* y terminan con *). No se puede anidar comentarios.  
 
<delphi>      {  (* (* *) *)</delphi>
 
<delphi>      {  (* (* *) *)</delphi>
 
will yield an error because the compiler matches the first '<tt>(*</tt>' with the first '<tt>*)</tt>', ignoring the second '<tt>(*</tt>' which is between the first set of comment markers. The second '<tt>*)</tt>' is left without its matching '<tt>(*</tt>'. This problem with begin-end comment markers is one reason why many languages use line-based commenting systems.
 
will yield an error because the compiler matches the first '<tt>(*</tt>' with the first '<tt>*)</tt>', ignoring the second '<tt>(*</tt>' which is between the first set of comment markers. The second '<tt>*)</tt>' is left without its matching '<tt>(*</tt>'. This problem with begin-end comment markers is one reason why many languages use line-based commenting systems.
Line 34: Line 30:
  
 
In addition, comments are often used to take problematic code out of action without deleting it. Remember the earlier restriction on nesting comments? It just so happens that braces <tt>{}</tt> take precedence over parentheses-stars <tt>(* *)</tt>. You will not get an error if you do this:
 
In addition, comments are often used to take problematic code out of action without deleting it. Remember the earlier restriction on nesting comments? It just so happens that braces <tt>{}</tt> take precedence over parentheses-stars <tt>(* *)</tt>. You will not get an error if you do this:
<delphi>
+
<delphi> { (* Comment *) }</delphi>
{ (* Comment *) }
 
</delphi>
 
  
 
Whitespace (spaces, tabs, and end-of-lines) are ignored by the Pascal compiler unless they are inside a literal string. However, to make your program readable by human beings, you should indent your statements and put separate statements on separate lines. Indentation is often an expression of individuality by programmers, but collaborative projects usually select one common style to allow everyone to work from the same page.
 
Whitespace (spaces, tabs, and end-of-lines) are ignored by the Pascal compiler unless they are inside a literal string. However, to make your program readable by human beings, you should indent your statements and put separate statements on separate lines. Indentation is often an expression of individuality by programmers, but collaborative projects usually select one common style to allow everyone to work from the same page.
  
 
{|style=color-backgroud="white" cellspacing="20"
 
{|style=color-backgroud="white" cellspacing="20"
|[[Hello, World|previous]]   
+
|[[Hello, World\es|previo]]   
|[[Contents|contents]]  
+
|[[Contents\es|índice]]  
|[[Identifiers|next]]
+
|[[Identifiers\es|siguiente]]
 
|}
 
|}

Revision as of 19:44, 7 May 2010

Bases 1A - Estructura de un Programa (author: Tao Yue, state: unchanged)

   La estructura básica de un programa Pascal es: <delphi> PROGRAM NombrePrograma (ListaArchivos);

CONST
 (* Declaración de Constantes *)
TYPE
 (* Declaración de Tipos *)
VAR
 (* Declaración de Variables *)
(* Definiciones de Subprogramas *)
BEGIN
 (* Sentencias ejecutables *)
END.</delphi>

   Los elementos del programa deben aparecer en el orden correcto, aunque pueden ser omitidos si no se necesitan.

   Aquí hay un programa que no hace nada, pero tiene todos los elementos necesarios: <delphi> program HacerNada;

begin
end.</delphi>

   Los comentarios son partes del código que no se compilan ni ejecutan. Los comentarios en Pascal comienzan con (* y terminan con *). No se puede anidar comentarios. <delphi> { (* (* *) *)</delphi> will yield an error because the compiler matches the first '(*' with the first '*)', ignoring the second '(*' which is between the first set of comment markers. The second '*)' is left without its matching '(*'. This problem with begin-end comment markers is one reason why many languages use line-based commenting systems.

Turbo Pascal and most other modern compilers support brace comments, such as {Comment}. The opening brace signifies the beginning of a block of comments, and the ending brace signifies the end of a block of comments. Brace comments are also used for compiler directives.

Commenting makes your code easier to understand. If you write your code without comments, you may come back to it weeks, months, or years later without a guide to why you coded the program that way. In particular, you may want to document the major design of your program and insert comments in your code when you deviate from that design for a good reason.

In addition, comments are often used to take problematic code out of action without deleting it. Remember the earlier restriction on nesting comments? It just so happens that braces {} take precedence over parentheses-stars (* *). You will not get an error if you do this: <delphi> { (* Comment *) }</delphi>

Whitespace (spaces, tabs, and end-of-lines) are ignored by the Pascal compiler unless they are inside a literal string. However, to make your program readable by human beings, you should indent your statements and put separate statements on separate lines. Indentation is often an expression of individuality by programmers, but collaborative projects usually select one common style to allow everyone to work from the same page.

previo índice siguiente