Basic Pascal Tutorial/Chapter 1/Program Structure/it

From Free Pascal wiki
Revision as of 12:00, 13 July 2016 by Razor (talk | contribs) (Created page with "{{Program Structure}} {{TYNavigator|Hello, World|Identifiers}} Fondamenti 1A - Struttura del programma (author: Tao Yue, state: changed) La struttura fondamentale di un prog...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

العربية (ar) български (bg) Deutsch (de) English (en) español (es) français (fr) italiano (it) 日本語 (ja) 한국어 (ko) русский (ru) 中文(中国大陆)‎ (zh_CN)

 ◄   ▲   ► 

Fondamenti 1A - Struttura del programma (author: Tao Yue, state: changed)

La struttura fondamentale di un programma Pascal è:

PROGRAM ProgramName (FileList);

CONST
  (* Constant declarations *)

TYPE
  (* Type declarations *)

VAR
  (* Variable declarations *)

(* Subprogram definitions *)

BEGIN
  (* Executable statements *)
END.

L'enunciato PROGRAM è opzionale in Free Pascal.

Gli elementi di un programma devono essere nell'ordine corretto, sebbene alcuni possano essere omessi se non necessari. Ecco un programma che non fa alcunché, ma include tutti gli elementi necessari:

program DoNothing;
begin
end.

I commenti sono porzioni di codice che non viene compilato né eseguito. Free Pascal supporta due tipi di commenti, "free-form" e "line-based". I commenti "free-form" possono cominciare con (* e terminare con *), oppure, più comunemente, iniziare con { e terminare con }. Non è possibile annidare commenti:

        (* (* *) *)

produrrà un errore poiché il compilatore assocerà il primo '(*' con il primo '*)', ignorando il secondo '(*' che si trova all'interno del primo insieme di marcatori di commento. Il secondo '*)' resterà privo del corrispondente '(*'. Questo problema con l'inizio e la fine dei marcatori di commento è una delle ragioni per cui molti linguaggi utilizzano sistemi di commento "line-based."

Free Pascal also supports // as a line-based comment. When two slashes appear, other than in a quoted string or a free-form comment, the rest of the line is ignored.

Turbo Pascal and most other modern compilers support free-form 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:

{ (* Comment *) }

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.

 ◄   ▲   ►