Basic Pascal Tutorial/Chapter 3/WHILE..DO/zh CN

From Lazarus wiki
(Redirected from WHILE..DO/zh CN)
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

български (bg) English (en) français (fr) 日本語 (ja) 中文(中国大陆)‎ (zh_CN)

3Db - WHILE..DO循环 (原作者: Tao Yue, 状态: 未更改)

先判断后循环:

while 逻辑表达式 do
  语句;

判断逻辑表达式为真,则继续执行循环;直至表达式为假将退出循环。

在循环体中你必须设法改变表达式的值(即,造成为假的条件),否则,它将是一个死循环:

a := 5;
while a < 6 do
  writeln (a);


通过改变变量,以避免循环:

a := 5;
while a < 6 do
begin
  writeln (a);
  a := a + 1
end;

WHILE...DO 称之为先判断后循环,即,在进入循环前,先判断条件是否为真,如果为假,将不会进入循环。

上一页 目录 下一页