Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 27 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
27
Dung lượng
340 KB
Nội dung
C++ Programming Lecture Control Structure II The Hashemite University (Repetition) Computer Engineering Department (Adapted from the textbook slides) Outline Introduction while Repetition Structure for Repetition Structure do/while Repetition Structure continue and break Statements Formulating Algorithms Nested Control Structures Examples The Hashemite University Introduction In the last lecture we have explored the selection control structures In this lecture we will explore another type of control structure in which part of the code is repeated number of times Repetition (or looping) control structures: while for do/while The Hashemite University Types of Looping Two types of repetition or looping exist: Sentinel-Controlled Repetition In this type you not know the number of times the body of the loop must be repeated, i.e not know the number of loop iterations Mainly you use while, and do/while control structures for this type of looping Counter-Controlled Repetition In this type you know the number of times the body of the loop must be repeated, i.e the number of loop iterations is defined in advance Mainly you use for control structures for this type of looping The Hashemite University 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 Another example int product = 2; while ( product