欢迎来到天天文库
浏览记录
ID:49311918
大小:1.53 MB
页数:32页
时间:2020-02-03
《Chapter4-ControlStructures-Repetition.ppt》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Copyright©2012PearsonEducation,Inc.Chapter4ControlStructures:RepetitionCopyright©2012PearsonEducation,Inc.OutlineObjectivesAlgorithmDevelopmentRepetitionStructuresProblemSolvingApplied:GPSDataC++breakandcontinueStatementsStructuringInputLoopsProblemSolvingApplied:WeatherBalloonsCopyright©2
2、012PearsonEducation,Inc.ObjectivesDevelopproblem-solvingsolutionsinC++containing:Repetitionstructuresthatallowustorepeatasetofstepsaslongasaconditionistrue.ThreecommonformsofinputloopsAlgorithmdevelopmentanddescriptionsofloopsusingflowchartsandpseudocode.AlgorithmDevelopmentCopyright©2012
3、PearsonEducation,Inc.Example:ComputingVelocityoveraRangeofTime.Sequentialstructuresarenotwellsuitedforcomputingthesamequantitiesrepeatedly.Flowchartsandpseudocodeareusefultodescriberepetition.Copyright©2012PearsonEducation,Inc.RepetitionStructuresCopyright©2012PearsonEducation,Inc.Thewhile
4、StatementCopyright©2012PearsonEducation,Inc.Syntax:while(boolean_expression)statement;while(boolean_expression){statement1;…statement_n;}Exampleswhile(!isspace(ch))cin.get(ch);//statementrepeateduntila//spacecharacterisreadwhile(x>y){//statementblockexecuted//whilex>0++cl;--x;}InfiniteLoo
5、psAninfiniteloopisoneinwhichtheloopconditionisalwaystrue.Selectiveexecutionofabreakstatementoraborting/exitingtheprogrammethodsofescapinganinfiniteloop.Copyright©2012PearsonEducation,Inc.AvoidingBugsWhenprogramminglongerprograms,itisnotuncommontohavealargenumberoferrormessagesfromthecomp
6、iler.Asingleerroroftencausesseveralerrorsasthecompilergets‘confused’overwhatfollowsanerror.Startcorrectingerrorsfromthetopoftheerrorlist,NOTthebottom.Recompileyourprogramfrequently,limitingtheplaceswhereerrorsmayoccur.Useendlindebuggingoutputstatementstobesurewhatyousendisactuallyseenonscr
7、een.Copyright©2012PearsonEducation,Inc.Thedo-whileStatementCopyright©2012PearsonEducation,Inc.Syntax:dostatement;while(boolean_expression);do{statement1;…statement_n;}while(boolean_expression);Examplesdocin.get(ch);//statementrepeateduntilanwhile(ch!=‘’)//ne
此文档下载收益归作者所有
点击更多查看相关文章~~