LectureSeven - Lecture 7 Control Structure I(Repetition –...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lecture 7 Control Structure I (Repetition) – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department 2 while Repetition Structure I ¡ Repetition structure ¡ Programmer specifies an action to be repeated while some condition remains true. ¡ Also called looping or simply loop. ¡ Psuedocode while there are more items on my shopping list Purchase next item and cross it off my list ¡ while loop repeated until condition becomes false where the next line of code after while loop will be executed. ¡ Example int product = 2; while ( product <= 1000 ) product = 2 * product; ¡ The body of the while loop is the code block contained within the braces after the while, otherwise it is the first statement after the while only. 3 while Repetition Structure II product <= 1000 product = 2 * product true false ¡ Flowchart of while loop. ¡ Infinite loop: ¡ Logical error in the while structure. ¡ The condition of the while is always true, i.e. the body of the while loop does modify the condition value. 4 Essentials of Counter-Controlled Repetition ¡ Counter-controlled repetition requires: ¡ The name of a control variable (or loop counter).The name of a control variable (or loop counter)....
View Full Document

{[ snackBarMessage ]}

Page1 / 13

LectureSeven - Lecture 7 Control Structure I(Repetition –...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online