1 / 14

# 循环语句 - PowerPoint PPT Presentation

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about '循环语句' - hovan

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

• 一、DO ……LOOP循环
• DO ……LOOP结构提供了一种基于某个条件的灵活的循环方法，它有四种形式，分别为：
• DO UNTIL condition …… LOOP
• DO WHILE condition …… LOOP
• DO …… LOOP UNTIL condition
• DO …… LOOP WHILE condition
• DO表示循环的开始，LOOP表示循环的结束，condition表示循环条件，是个逻辑表达式，其值为True或False。

1、DO UNTIL condition ……LOOP的语法格式为：

DO UNTIL condition statements LOOP

int sum=0,x=0

do until x>100

if x%2=0 then

sum+=x

end if

x++

loop

DO WHILE condition statements LOOP

int sum=0,x=0

do while x<=100

sum+=x

x++

loop

3、DO …… LOOP UNTIL condition的语法格式为：DO statements LOOP UNTIL condition

int sum=0,x=0

do

if x%2<>0 then

sum+=x

end if

x++

loop until x>100

4、DO……LOOP WHILE condition的语法格式为：

DO statements LOOP WHILE condition

int i=1，sum=1

do

sum*=I

i+=2

loop while i<=100

FOR ……NEXT是个循环次数确定的循环结构，它使循环体内的语句执行规定的次数。

FOR varname = start TO end [STEP increment] statementblock

NEXT

integer i，sum=0

for i=1 to 100

sum += i

next

1、求斐伯那契数列的前N项和

1、1、2、3、5、8、13、21、34、55、……

2、屏幕保护程序

Fbef=1 Fbed=1

int sum=2

For i=3 to 10

fnext=fbef+fbed

sum+=f3

fbef=fbed

fbed=fnext

next

do while count<11

if Nbr[Count] = 0 then EXIT

Count = Count + 1

loop

MessageBox("提示", "Count的值为 " + String(Count) )

for index=1 to 3000

if item[index]="" then

CONTINUE

……

next

int i , j

for i = 1 to 2 //外层循环

for j = 1 to 3 //内层循环

Matrix[i,j]=i+j

next //j,内层循环结束

next //i, 外层循环结束

15 23 11 45 20 78 99 36 24 17

99 23 11 45 20 78 15 36 24 17

99 78 11 45 20 23 15 36 24 17

99 78 45 11 20 23 15 36 24 17

99 78 45 36 20 23 15 11 24 17

99 78 45 36 24 23 15 11 20 17

99 78 45 36 24 23 15 11 20 17

99 78 45 36 24 23 20 11 15 17

99 78 45 36 24 23 20 17 15 11

j

15 23 11 45 20 78 99 36 24 17

max=i