do循环4种结构的比较

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

DO循环四种结构比较

(1) i=inputbox(“请输入I的值”)

do while i<=10

I=i+1

Loop

Print i

程序运行结果___________

(2) i=inputbox(“请输入I的值”)

Do

I=i+1

Loop while i<=10

Print i

程序运行结果___________

(3) i = InputBox(“请输入I的值”)

Do Until i > 10

i = i + 1

Loop

Print i

(4)i = InputBox(“请输入I的值”)

Do

i = i + 1

Loop Until i > 10

Print i

1、Do until-loop 结构

Private Sub Command1_Click()

Dim m As Integer, i As Integer

m = InputBox("请输入一个数:")

i = 2

Do Until (m Mod i = 0) Or i = m - 1

i = i + 1

Loop

If m Mod i = 0 Then

Print m; "不是素数"

Else

Print m; "是素数"

End If

End Sub

2、Do while –loop 结构

Private Sub Command1_Click()

m = InputBox("请输入大于2的任意自然数")

i = 2

Do While (m Mod i <> 0) And (i < m - 1)

i = i + 1

Loop

If m Mod i = 0 Then

Print m; "不是素数"

Else

Print m; "是素数"

End If

End Sub

3、Do –loop while

Private Sub Command1_Click()

Dim m As Integer, i As Integer

m = InputBox("请输入一个数:")

i = 2

Do

If m Mod i <> 0 Or i < m - 1 Then

i = i + 1

End If

Loop While m Mod i <> 0 And i < m - 1 If m Mod i = 0 Then

Print m; "不是素数"

Else

Print m; "是素数"

End If

End Sub

4、Do-loop until Private Sub Command1_Click()

Dim m As Integer, i As Integer

m = InputBox("请输入一个数:")

i = 2

Do

If m Mod i <> 0 Or i < m - 1 Then

i = i + 1

End If

Loop Until m Mod i = 0 Or i >= m - 1

If m Mod i = 0 Then

Print m; "不是素数"

Else

Print m; "是素数" End If

End Sub

相关文档
最新文档