Object Oriented Design and ProgrammingWeek 4A B Emran Salahuddin (Sydney)Manzur Ashraf (Melbourne)Kent Institute Australia Pty. Ltd.ABN 49 003 577 302 CRICOS Code: 00161ERTO Code: 90458 TEQSA Provider Number: PRV12051Version 2 – 18thDecember 2015
SLIDE TITLEFarrell, J. (2017) Programming Logic and Design, Comprehensive (9th ed.) Cengage Learning 2
Programming Logic and DesignNinth EditionChapter 5Understanding Programming Structures3Programming Logic and Design, Ninth Edition
Objectives•Programming Structure-LoopingWhile loopDo-while loopFor loopCombination of programming structuresUnderstanding the Reasons for Structure4Programming Logic and Design, Ninth Edition
The Loop Structure•Loop structure•Repeats a set of actions while a condition remains true•Loop body•Also called repetitionor iteration•Condition is tested first in the most common form of loop•The while…door whileloop or for loop5Programming Logic and Design, Ninth Edition
The Loop Structure (continued -2)•Loop structurewhiletestCondition continues to be truedosomeProcess endwhilewhileyou continue to be hungrytake another bite of fooddetermine if you still feel hungryendwhile6Programming Logic and Design, Ninth Edition
The Loop Structure (continued -3)while loop•Ask a question and, depending on the answer, you might or might not enter the loop to execute the loop’s procedure.•A while loop is also called a pretest loop because a condition is tested before entering the loop even once. 7Programming Logic and Design, Ninth Edition
The Loop Structure (continued -4)while loop•The important point to note when using while loop: •Use increment or decrement statement inside while loop •Loop variable gets changed on each iteration•And at some point condition returns false•This way we can end the execution of while loop otherwise the loop would execute indefinitely.