
- Pascal 教程
- Pascal - 首頁
- Pascal - 概述
- Pascal - 環境設定
- Pascal - 程式結構
- Pascal - 基本語法
- Pascal - 資料型別
- Pascal - 變數型別
- Pascal - 常量
- Pascal - 運算子
- Pascal - 決策
- Pascal - 迴圈
- Pascal - 函式
- Pascal - 過程
- Pascal - 變數作用域
- Pascal - 字串
- Pascal - 布林值
- Pascal - 陣列
- Pascal - 指標
- Pascal - 記錄
- Pascal - 變體
- Pascal - 集合
- Pascal - 檔案處理
- Pascal - 記憶體
- Pascal - 單元
- Pascal - 日期和時間
- Pascal - 物件
- Pascal - 類
- Pascal 有用資源
- Pascal - 快速指南
- Pascal - 有用資源
- Pascal - 討論
Pascal - 基本語法
您已經瞭解了 Pascal 程式的基本結構,因此很容易理解 Pascal 程式語言的其他基本構建塊。
變數
變數定義放在以var關鍵字開頭的塊中,然後按如下方式定義變數
var A_Variable, B_Variable ... : Variable_Type;
Pascal 變數宣告在函式的程式碼體之外,這意味著它們不是在begin和end對內宣告的,而是在過程/函式定義之後以及begin關鍵字之前宣告的。對於全域性變數,它們在程式頭之後定義。
函式/過程
在 Pascal 中,過程是一組要執行的指令,沒有返回值;函式是一個有返回值的過程。函式/過程的定義如下:
Function Func_Name(params...) : Return_Value; Procedure Proc_Name(params...);
註釋
多行註釋用花括號和星號括起來,例如 (* ... *)。Pascal 允許用花括號括起來單行註釋,例如 { ... }。
(* This is a multi-line comments and it will span multiple lines. *) { This is a single line comment in pascal }
大小寫敏感性
Pascal 是一種不區分大小寫的語言,這意味著您可以使用任何大小寫編寫變數、函式和過程。例如,變數 A_Variable、a_variable 和 A_VARIABLE 在 Pascal 中具有相同的含義。
Pascal 語句
Pascal 程式由語句組成。每個語句都指定程式的特定任務。這些任務可以是宣告、賦值、讀取資料、寫入資料、進行邏輯決策、轉移程式流程控制等。
例如:
readln (a, b, c); s := (a + b + c)/2.0; area := sqrt(s * (s - a)*(s-b)*(s-c)); writeln(area);
Pascal 保留字
Pascal 中的語句是用一些特定的 Pascal 詞設計的,這些詞稱為保留字。例如,program、input、output、var、real、begin、readline、writeline 和 end 都是保留字。
以下是 Pascal 中保留字的列表。
and | array | begin | case | const |
div | do | downto | else | end |
file | for | function | goto | if |
in | label | mod | nil | not |
of | or | packed | procedure | program |
record | repeat | set | then | to |
type | until | var | while | with |
Pascal 字元集和識別符號
Pascal 字元集包含:
所有大寫字母 (A-Z)
所有小寫字母 (a-z)
所有數字 (0-9)
特殊符號 - + * / := , . ;. () [] = {} ` 空格
Pascal 程式中的實體,如變數和常量、型別、函式、過程和記錄等,都有一個名稱或識別符號。識別符號是由字母和數字組成的序列,以字母開頭。特殊符號和空格不能用在識別符號中。