




已阅读5页,还剩35页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Chapter6 TheRepetitionStructure ProgrammingwithMicrosoftVisualBasic NET SecondEdition ProgrammingwithMicrosoftVisualBasic NET SecondEdition 2 TheRepetitionStructure Looping LessonAObjectives CodetherepetitionstructureusingtheFor NextandDo LoopstatementsWritepseudocodefortherepetitionstructureCreateaflowchartfortherepetitionstructureInitializeandupdatecountersandaccumulators ProgrammingwithMicrosoftVisualBasic NET SecondEdition 3 TheRepetitionStructure Usetherepetitionstructuretorepeatedlyprocessoneormoreprograminstructionsuntilsomeconditionismet atwhichtimetherepetitionendsTherepetitionstructureisreferredtoasaloop ProgrammingwithMicrosoftVisualBasic NET SecondEdition 4 TheRepetitionStructure continued Pretestloop evaluationoccursbeforetheinstructionswithintheloopareprocessedPosttestloop evaluationoccursaftertheinstructionswithintheloopareprocessed ProgrammingwithMicrosoftVisualBasic NET SecondEdition 5 TheFor NextLoop UsetheFor Nextstatementtocodealoopthatrepeatsforaspecificnumberoftimes Figure6 2 SyntaxandexamplesoftheFor Nextstatement ProgrammingwithMicrosoftVisualBasic NET SecondEdition 6 TheFor NextLoop continued Figure6 2 SyntaxandexamplesoftheFor Nextstatement continued ProgrammingwithMicrosoftVisualBasic NET SecondEdition 7 TheFor NextLoop continued counterisanumericvariablethatkeepstrackofhowmanytimestheloopinstructionsarerepeatedstartvalue endvalue andstepvalueMustbenumericCanbepositiveornegative integerornon integerDefaultstepvalueis1 ProgrammingwithMicrosoftVisualBasic NET SecondEdition 8 TheFor NextLoop continued Figure6 4 PseudocodeandflowchartforthefirstexampleshowninFigure6 2 ProgrammingwithMicrosoftVisualBasic NET SecondEdition 9 TheFor NextLoop continued For Nextloopexamples ProgrammingwithMicrosoftVisualBasic NET SecondEdition 10 TheDo LoopStatement UnliketheFor Nextstatement theDo LoopstatementcanbeusedtocodebothapretestloopandaposttestloopTheDo LoopstatementbeginswiththeDoclauseandendswiththeLoopclause ProgrammingwithMicrosoftVisualBasic NET SecondEdition 11 TheDo LoopStatement continued Figure6 7 SyntaxandexamplesoftheDo Loopstatement ProgrammingwithMicrosoftVisualBasic NET SecondEdition 12 TheDo LoopStatement continued Figure6 7 SyntaxandexamplesoftheDo Loopstatement continued ProgrammingwithMicrosoftVisualBasic NET SecondEdition 13 TheDo LoopStatement continued Figure6 9 FlowchartsfortheexamplesshowninFigure6 7 ProgrammingwithMicrosoftVisualBasic NET SecondEdition 14 TheDo LoopStatement continued Figure6 9 FlowchartsfortheexamplesshowninFigure6 7 continued ProgrammingwithMicrosoftVisualBasic NET SecondEdition 15 UsingCountersandAccumulators Countersandaccumulatorsareusedwithinarepetitionstructuretocalculatesubtotals totals andaveragesAcounterisanumericvariableusedforcountingsomethingandistypicallyupdatedby1Anaccumulatorisanumericvariableusedforaccumulatingandisupdatedbyanamountthatvaries ProgrammingwithMicrosoftVisualBasic NET SecondEdition 16 UsingCountersandAccumulators continued Initializing assigningabeginningvaluetothecounteroraccumulatorUpdating incrementing addinganumbertothevaluestoredinthecounteroraccumulator ProgrammingwithMicrosoftVisualBasic NET SecondEdition 17 NestedRepetitionStructuresLessonBObjectives Nestrepetitionstructures ProgrammingwithMicrosoftVisualBasic NET SecondEdition 18 NestingRepetitionStructures Inanestedrepetitionstructure oneloop referredtoastheinnerloop isplacedentirelywithinanotherloop calledtheouterloopAclockusesnestedloopstokeeptrackofthetime ProgrammingwithMicrosoftVisualBasic NET SecondEdition 19 NestingRepetitionStructures continued Figure6 16 Nestedloopsusedbyaclock ProgrammingwithMicrosoftVisualBasic NET SecondEdition 20 TheGradeCalculatorApplication ProfessorArkinsneedsanapplicationthatallowshimtoassignagradetoanynumberofstudentsEachstudent sgradeisbasedonthreetestscores witheachtestworth100pointsTheapplicationshouldtotalthetestscoresandthenassigntheappropriategrade usingthetableshownonthenextslide ProgrammingwithMicrosoftVisualBasic NET SecondEdition 21 TheGradeCalculatorApplication continued ProgrammingwithMicrosoftVisualBasic NET SecondEdition 22 TheGradeCalculatorApplication continued uiAssignGradeButton sClickeventprocedureAllowsProfessorArkinstoentereachstudent stestscores andthenassigntheappropriategradeContainstwoloops onenestedwithintheotherAFor Nextstatementcontrolstheinnerloop ProgrammingwithMicrosoftVisualBasic NET SecondEdition 23 TheGradeCalculatorApplication continued uiAssignGradeButton sClickeventprocedure continued ADo LoopstatementcontrolstheouterloopTheinnerloopisapretestloopTheouterloopisaposttestloop ProgrammingwithMicrosoftVisualBasic NET SecondEdition 24 TheGradeCalculatorApplication continued Figure6 20 Samplerunoftheapplicationthatcontainstheprocedure ProgrammingwithMicrosoftVisualBasic NET SecondEdition 25 CodingtheShoppersHavenApplicationLessonCObjectives SelecttheexistingtextinatextboxPreventaformfromclosing ProgrammingwithMicrosoftVisualBasic NET SecondEdition 26 ShoppersHaven ThemanagerofShoppersHavenwantsanapplicationthatthestoreclerkscanusetocalculatethediscountedpriceofanitem usingdiscountratesfrom10 through30 inincrementsof5 Theclerkswillentertheitem soriginalpriceTheapplicationshoulddisplaythediscountratesandthediscountedpricesintheinterface ProgrammingwithMicrosoftVisualBasic NET SecondEdition 27 ShoppersHaven continued Figure6 21 UserinterfacefortheShoppersHavenapplication ProgrammingwithMicrosoftVisualBasic NET SecondEdition 28 ShoppersHaven continued Figure6 22 TOEchartfortheShoppersHavenapplication ProgrammingwithMicrosoftVisualBasic NET SecondEdition 29 ShoppersHaven continued Figure6 23 PseudocodefortheCalculatebutton sClickeventprocedure ProgrammingwithMicrosoftVisualBasic NET SecondEdition 30 ShoppersHaven continued Figure6 27 DiscountedpricesshownintheShoppersHavenapplication ProgrammingwithMicrosoftVisualBasic NET SecondEdition 31 SelectingtheExistingTextinaTextBox UsetheSelectAllmethodtoselectallofthetextcontainedinatextboxSyntax textbox SelectAll textboxisthenameofthetextboxwhosetextyouwanttoselect ProgrammingwithMicrosoftVisualBasic NET SecondEdition 32 SelectingtheExistingTextinaTextBox continued EntertheSelectAllmethodinatextboxcontrol sEntereventAtextboxcontrol sEntereventoccurswhentheusertabstothecontrol andwhentheFocusmethodisusedincodetosendthefocustothecontrolTheuiOriginalTextBoxcontrol sEntereventisresponsibleforhighlightingtheexistingtextinthecontrol ProgrammingwithMicrosoftVisualBasic NET SecondEdition 33 SelectingtheExistingTextinaTextBox continued Figure6 29 TextselectedintheShoppersHavenapplication ProgrammingwithMicrosoftVisualBasic NET SecondEdition 34 CodingtheTextChangedEventProcedure Acontrol sTextChangedeventoccurswhenthecontentsofacontrol sTextpropertychangeUsetheuiOriginalTextBox sTextChangedeventtoclearthecontentsoftheuiDiscPricesLabelwhentheuserchangestheoriginalprice ProgrammingwithMicrosoftVisualBasic NET SecondEdition 35 CodingtheShoppersForm sClosingEventProcedure Aform sClosingeventoccurswhenaformisabouttobeclosedIntheShoppersHavenapplication theClosingeventprocedureisresponsiblefor VerifyingthattheuserwantstoexittheapplicationTakinganactionbasedontheuser sresponse ProgrammingwithMicrosoftVisualBasic NET SecondEdition 36 CodingtheShoppersForm sClosingEventProcedure continued Figure6 31 PseudocodefortheShoppersForm sClosingeventprocedure ProgrammingwithMicrosoftVisualBasic NET SecondEdition 37 CodingtheShoppersForm sClosingEventProcedure continued Figure6 33 Messageboxdisplayedbytheform sClosingevent ProgrammingwithMicrosoftVisualBasic NET SecondEdition 38
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度湖北省发展和改革委员会考试录用公务员专业测试模拟试卷及答案详解(新)
- 2025内蒙古民航机场集团有限公司招聘76人考前自测高频考点模拟试题及答案详解(名校卷)
- 2025广东广州市增城区遴选储备村级后备干部考前自测高频考点模拟试题及一套参考答案详解
- 2025年甘肃省兰州大学土木工程与力学学院聘用制(B岗)人员招聘模拟试卷有完整答案详解
- 2025国网中国电力科学研究院有限公司第二批高校毕业生录用人选的模拟试卷及答案详解(新)
- 2025内蒙古赤峰市喀喇沁旗锦山第三中学“绿色通道”引进教师第二次3人模拟试卷附答案详解(典型题)
- 2025杭州青少年活动中心招聘工勤岗位工作人员20人模拟试卷附答案详解
- 2025贵州省科学技术协会招聘直属事业单位工作人员模拟试卷及答案详解(新)
- 2025广西壮族自治区中医骨伤科研究所广西骨伤医院招聘实名编制人员(高级职称)3人模拟试卷参考答案详解
- 2025安徽宣城市广德市国有资产投资经营有限公司下属公司招聘11人模拟试卷及答案详解(名校卷)
- 法治护航-健康成长课件
- 口令信息安全管理办法
- 护理重点专科评审解读
- 内科消化道出血诊疗规范
- 时空数据建模与预测算法-洞察阐释
- 城市污水处理厂运行承诺及保障措施
- 2025年长江引航中心招聘笔试备考题库(带答案详解)
- 压力性损伤的个案护理
- 2025-2030中国生物石脑油市场发展现状与未来前景动态研究报告
- 织补培训课件
- 儿童肺功能检查课件
评论
0/150
提交评论