枚举结构(二)——选择结构和循环结构复习课件(15张幻灯片)

文档属性

名称 枚举结构(二)——选择结构和循环结构复习课件(15张幻灯片)
格式 zip
文件大小 308.8KB
资源类型 教案
版本资源 浙教版
科目 信息技术(信息科技)
更新时间 2019-06-27 14:00:02

图片预览

文档简介

课件15张PPT。VB复习(二)
——选择语句和循环语句单击此处添加标题Part 4选择语句01格式1:行If语句1、If 条件表达式 Then 语句
2、If 条件表达式 Then 语句1 Else 语句2格式2:块If语句If 条件表达式1 Then
   语句块1
ElseIf 条件表达式2  Then
  语句块2
  ……
ElseIf 条件表达式n  Then
  语句块n
Else
  语句块0
End If1、If 条件表达式 Then 语句
2、If 条件表达式 Then 语句1 Else 语句2If 条件表达式1 Then
   语句块1
ElseIf 条件表达式2  Then
  语句块2
  ……
ElseIf 条件表达式n  Then
  语句块n
Else
  语句块0
End If格式1:行If语句格式2:块If语句怎么区分行If语句和块If语句?格式1:行if语句
Private Sub Command1_Click()
Dim x As Single, y As Single
x = Val(Text1.Text)
----______________________________________
Label5.Caption = " y=" + Str(y)
End SubIf x<0 Then y=x+1 Else y=2*x+3格式2:块if语句
Private Sub Command2_Click()
Dim x As Single, y As Single
x = Val(Text1.Text)
_____________________
___________________
_________
_____________________
_________
Label5.Caption = " y=" + Str(y)
End SubIf x<0 Then
y=x+1
Else
y=2*x+3
End IfPrivate Sub Command1_Click()
Dim x As Single, y As Single
x = Val(Text1.Text)
If ________________ Then
y = 1
______________
y = x ^ 2 + 3
Else
y = ____________
___________
Label5.Caption = "计算结果为:y=" + Str(y)
End Sub0<=x And x<1ElseIf x<0 Then5*x+3End If循环语句02For 循环变量 = 初值 To 终值 Step 步长
语句块
Next 循环变量Do While 条件表达式
  语句块
Loop格式1:For语句格式2:Do语句方法1:For语句
Private Sub Command1_Click()
Dim s As Integer, i As Integer
________________
________________
_________
Label2.Caption = "用for语句计算s=" + Str(s)
End Sub方法2:Do语句
Private Sub Command2_Click()
Dim s As Integer, i As Integer
i = _______
Do While _________
_________
_________
_________
Label2.Caption = "用do语句计算s=" + Str(s)
End SubFor i=1 To 11 Step 2Next is=s+i方法1:For语句
Private Sub Command1_Click()
Dim s As Integer, i As Integer
________________
________________
_________
Label2.Caption = "用for语句计算s=" + Str(s)
End Sub方法2:Do语句
Private Sub Command2_Click()
Dim s As Integer, i As Integer
i = _______
Do While _________
_________
_________
_________
Label2.Caption = "用do语句计算s=" + Str(s)
End SubFor i=1 To 11 Step 2Next is=s+i1i<=11s=s+ii=i+2Loop方法1:For语句
Private Sub Command1_Click()
Dim sum As Single, i As Integer
sum = 0
For _____________
____________________
Next _____
Label2.Caption = "For语句计算sum=" + Str(sum)
End Sub方法2:Do语句
Private Sub Command2_Click()
Dim sum As Single, i As Integer
sum = 0
___________
Do While ___________
____________________
_____________
Loop
Label2.Caption = "Do语句计算sum=" + Str(sum)
End Subi=1 To 4sum=sum+i/(i+1)ii=1 i<=4 sum=sum+i/(i+1)i=i+1综合练习03Private Sub Command1_Click()
Dim x As Integer, n As Integer, a As Integer, b As Integer
n = 0
For x = ①
a = ② 'a为十位上的数字
b = ③ 'b为个位上的数字
If ④ Then
List1.AddItem Str(x)

End If
Next x
Label2.Caption = "共有“over”数为:" + Str(n)
End Sub
有几个学生在玩报数游戏,游戏规则如下:1~99报数,首先从1开始报数,凡是报到3的倍数或数中包含数字3时,不能报出该数,要说“over”,否则将被淘汰出局。小明编写了一个报数游戏的VB程序,程序的功能为:单击“开始”按钮,将在列表框List1中输出“over”数,在标签Label3中显示“over”数的个数。程序运行效果如图所示。