1、单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,猜:,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,(,如果,那么,否则,),V,B,中的选择语句,IF,语句,用来解决有关选择结构的问题。,选择结构与选择语句,i
2、f,条件,then,语句,A,end if,if,条件,then,语句,A,else,语句,B,end if,If,和,end if,要成对出现,例,1,:,输入一个数到变量,a,,输出它的绝对值(不用绝对值函数),if,_,then,_,end if,a0,a=-a,Print,意为打印,是输出语句。,ab,print a,print b,ab,练习,1,:,输入两个不相等的数,a,,,b,,比较大小,将大数放在,a,中,小数放在,b,中,然后输出,a,,,b,if,_,then,_,end if,a0,0,x=0,-1,x0,if,_,then,_,else,if,_,then,_,els
3、e,_,end if,end if,print y,x0,y=1,y=-1,x=0,y=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 if,if,条件,1,then,语句,1,else,if,条件,2,then,语句,2,else,语句,3,end if,end if,小结,双分支嵌套双分支,温馨提示:,下节课在机房(,F405,)上课,记得带上练习纸和鞋套。,