VB中的IF语句

文档属性

名称 VB中的IF语句
格式 zip
文件大小 709.3KB
资源类型 教案
版本资源 浙教版
科目 信息技术(信息科技)
更新时间 2013-01-10 21:46:26

图片预览

文档简介

课件15张PPT。猜:VB 编 程IF语句英译汉:If the weather is good tomorrow, then I will go to the park.
If the weather is good tomorrow, then I will go to the park, else I have to stay at home.If ······then ······ (如果······那么······)If······ then······ else······ (如果······那么······否则······)VB中的选择语句 ——IF语句用来解决有关选择结构的问题。选择结构与选择语句
if 条件 then
语句A
end if

if 条件 then
语句A
else
语句B
end if
If和end if 要成对出现例1:输入一个数到变量a,输出它的绝对值(不用绝对值函数)if ____ then
____
end if a<0a=-aPrint 意为打印,是输出语句。a<0a = inputbox("")print a例2:从键盘分别输入两个不相等的数到变量a、b,输出其中较大的数。 if ____ then
____
else
____
end if a>bprint aprint ba>b练习1:输入两个不相等的数a,b,比较大小,将大数放在a中,小数放在b中,然后输出a,b if ____ then
__________
end if a类型有多种,比如:单分支嵌套单分支、双分支嵌套双分支等嵌套分支结构单分支嵌套单分支双分支嵌套双分支例3:已知分段函数y= ,输出y的值。1 , x>00 , x=0-1 , x<0if ____ then
____
else
if ____ then
____
else
____
end if
end if
print yx<0y=1y=-1x=0y=0分支结构1分支结构2分支嵌套——双分支嵌套双分支if 条件1 then
语句1
else
if 条件2 then
语句2
else
语句3
end if
end if分



1分



2注意:每一层的end if结束本层判断。练习2: 购买地铁车票,若乘1—4站,3元/位;若乘5—9站,4元/位;若乘10站以上,5元/位;输入人数person、站数n,输出应付款pay。流程图程序代码if n<=4 then
pay=3*person
else
if n<=9 then
pay=4*person
else
pay=5*person
end if
end if
print pay选择结构单分支结构双分支结构嵌套分支结构 if 条件 then
语句A
end if if 条件 then
语句A
else
语句B
end ifif 条件1 then
语句1
else
if 条件2 then
语句2
else
语句3
end if
end if小结双分支嵌套双分支