(10.5.1)--8.5For...NextStatements.ppt

上传人:刘静 文档编号:84102259 上传时间:2023-04-01 格式:PPT 页数:10 大小:351.82KB
返回 下载 相关 举报
(10.5.1)--8.5For...NextStatements.ppt_第1页
第1页 / 共10页
(10.5.1)--8.5For...NextStatements.ppt_第2页
第2页 / 共10页
点击查看更多>>
资源描述

《(10.5.1)--8.5For...NextStatements.ppt》由会员分享,可在线阅读,更多相关《(10.5.1)--8.5For...NextStatements.ppt(10页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、For.Next Loop数据库技术与程序设计Loop StructureWhile programming,we often facing a situation where a While programming,we often facing a situation where a repeated execution is always needed.repeated execution is always needed.The Loop Structure can meet the demands.The Loop Structure can meet the demands.The

2、 Loop Structure The Loop Structure can control the repeated execution of a can control the repeated execution of a certain part of the statements sequence in the program by certain part of the statements sequence in the program by specifiying the current value of the given conditions.specifiying the

3、 current value of the given conditions.数据库技术与程序设计Loop Structure VBA provides four loop statements:,which are:Do While.LoopDo While.LoopFor.NextFor.NextWhile.WendWhile.WendDo Until.LoopDo Until.Loop数据库技术与程序设计ForNext StatementForNext Loop is also called numeric for-loops.SyntaxFor =To Step statements

4、Exit For statementsNext counterExecution:the VBA will first calculate the counters start,end and step as well as assign initial value to the counter.Then it compares the counter(assigned value already)with end.If the counter is less than end(only if step is positive or 0),or more than/equal to end(o

5、nly if step negative),the VBA will execute the statements between For and Next,namely the loop.The counter will automatically add a value of step wherever it encounters Next and compares itself with end again.The loop constantly repeats itself again and again and will not stop until value in the cou

6、nter exceeds end.counter=start statementscounter=counter+stepcounter start数据库技术与程序设计ForNext StatementExampleOutputting four“*”in one line in Immediate Window,which can be achieved by following program.Public Sub example1()Dim i As IntegerFor i=1 To 4 Step 1Debug.Print*;Adding“;”after output statemen

7、t means the next output will follow the same line as the former instead of beginning a new line.NextDebug.Print EndEnd Sub数据库技术与程序设计ForNext Statement数据库技术与程序设计ForNext StatementExampleRewrite the statements above so as to output strings“1 2 3 4”in only one line in Immediate Window.This statement can

8、be achieved by the following program:Public Sub example2()Dim i As IntegerFor i=1 To 4 Step 1Debug.Print i;Note:add“;”at the end of the output statement.NextDebug.Print endEnd Sub数据库技术与程序设计ForNext Statement数据库技术与程序设计ForNext StatementQuestion:Find the largest integer within 100 which is divisible by

9、7.(Use For Next Statement)Attention:Loop from the minimum to maximum,or conversely?Step can be a negative.Exit For Provides an immediate way to exit a For Loop数据库技术与程序设计ForNext StatementPublic Sub example3()Dim n As Integer For n=100 To 1 Step-1 If n Mod 7=0 Then Debug.Print n Exit For End If NextEnd Sub

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com