Các câu lệnh trong pascal

if then ;If the condition is true, then persize the job (opposite condition is false does not vì chưng the job).

Bạn đang xem: Các câu lệnh trong pascal

b. Full formatSyntax:

if then else ;If the condition is true, then persize the job 1, opposite condition is false, the execution of work 2.Note before ELSE no sign ; (semicolon).

* If the job done from 2 one or more commands to lớn put them in the BEGIN and END keywords pair;

2. Select statement

the. Incomplete formSyntax:

case ofHang_1: ;Hang_2: ;...Hang_n: ;end;If the value of the constant expression does fall inkhổng lồ the respective sầu construction will be carried out before the kết thúc of the case statement.If the value of the expression does not equal a constant case of the commvà ends without doing anything.

b. Full formatSyntax:

case ofHang_1: ;Hang_2: ;...Hang_n: else ;end;If the value of the constant expression does fall inlớn the respective construction will be carried out before the kết thúc of the case statement.If the value of the expression does not equal a constant will persize the first n 1 & exit.

Xem thêm: Bài Viết Về Kỳ Nghỉ Bằng Tiếng Anh Về Kỳ Nghỉ Hè Lý Thú, Sôi Động (Có Dịch)

Noted:+ The value hang_1, hang_2,…,hang_n be counted style (not the type of real).+ The value hang_1, hang_2,…,hang_n can be enumerated type or the paragraph style

Example:enumeration: 1,3,5,7the,c,dthe paragraph style: 1..10 (2 dots)a..z

3. The statement said the number of times previous iteration

the. Type 1:

for := to lớn do;– Step 1: Cheông xã first with values – Step 2: Cheông xã the value of the variable (other) over value or not. If true, the increased processing unit (well:= NEXT(well)) & perform the work.– Repeat steps 2, until the value of the variable with the value of the end of the kết thúc of the statement.Noted:Turn right after the từ khóa for the counter and started khổng lồ value

b. Type 2:

for := downlớn do;– Step 1: Cheông chồng first with values >= (less than or equal) kết thúc value or not. If true, then assign values ​​to lớn variables và execute the first task.– Step 2: Cheông chồng the value of the variable (other) over value or not. If true, then turn down to a reduction unit(well:PRE =(well)) và persize the work.– Repeat steps 2, until the value of the variable with the value of the over of the kết thúc of the statement.Noted:Turn right after the từ khoá for the counter and started lớn value >= Value over.

Noted: Unlượt thích other languages, Pascal is not checked (variable>final) in commvà FOR ... TO ... DO loop to the over that the thử nghiệm (variable = end) lớn perform the final iteration. Therefore the intervention on the counter can cause problems "endless loop". Even when the amplitude was browsing through all the range of data types (Instant values 255) Baông chồng Dynamics of value 0 ... And everything again ... unless typing Ctrl – Break.

4. The command loop with unknown number of times before

the. WHILE loopSyntax:

while do;When met loop program will check conditions, if the condition is true, then exexinh tươi the job, then baông xã khổng lồ kiểm tra conditions. Just continue lớn bởi so until the condition is false, the end.While the condition is true, the work.

b. REPEAT loop

Syntax:

repeatwriteln("i =",i);i:=i+1;until i>10;When meeting program loop will exexinh đẹp the work, then check the condition, if the condition is false, then continue khổng lồ vì chưng the work then kiểm tra the condition. Just continue lớn bởi vì so until the condition is true, the over. Work until the condition is true.

Xem thêm: Xem Phim Gia Đình Phép Thuật Bước Qua Tập Thứ 100, Gia Đình Phép Thuật Bước Qua Tập Thứ 100

Noted:

+ Unlike the loop Both loops While loops và Repeat are not predetermined number of iterations. Need a command lớn change the value of the variable control loop to lớn exit the loop.+ Within the while statement, the condition will be checked before, if the condition is true, then perform the job. And in the opposite order repeat, work is done first & then kiểm tra conditions, if the condition is true, the loop ends. So to lớn never repeat loop the loop toàn thân is also carried out at least once, while the toàn thân while loop can not be done any time.+ If the user 2 order khổng lồ solve the same problem, the same algorithm as the same condition after a while & then off until conditions are different negative sầu.+ The statements in the loop repeat do not need khổng lồ put in the keywords BEGIN và END pairs;

*

* Some other commands related

the. Goto– Syntax: goto label;In that label is a label, label name is set by naming known or an integer from 0 khổng lồ 9999– Action: Upon meeting the program goto lớn unconditional jump to lớn the statement after the label.– Noted: Golớn allowed to jump from one location to lớn another location within the same 1 function body, procedures, jumping out of the loop, not allowed to lớn jump from outside lớn inside the loop, jaw, procedures, bloông xã command

b. Break statement– Syntax: break;– Action: break statement works when placed in the body of the loop, while, repeat. When having a break statement; the machine will exit the loop cycle, If there are multiple nested loop will exit loop containing the break statement;

c. Exit– Syntax: Exit;– Action: Exit comm& will terminate the program if it is placed in ctc, terminate the program if it is in the main program

d. Halternative text command– Syntax: just;– Action: Upon meeting the halt commvà, the machine will stop running programs. This comm& is often used when the algorithm meet 1 TH can not continue to lớn be.


Chuyên mục: Tổng hợp