1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Chap5 slides

58 1 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 58
Dung lượng 277,74 KB

Nội dung

Chap5 slides [Compatibility Mode] Programming Fundamentals 1 Chapter 5 REPETITION STRUCTURES Programming Fundamentals 2 Chapter 5 n while loops n Interactive while loops n for loops n Nested loops n d[.]

Chapter REPETITION STRUCTURES Programming Fundamentals Chapter n n n n n n n n while loops Interactive while loops for loops Nested loops do-while Loops Structured programming with C++ Arrays Structures Programming Fundamentals Overview n C++ provides three different forms of repetition structures: while structure for structure do-while structure n Each of these structures requires a condition that must be evaluated n The condition can be tested at either (1) the beginning or (2) the end of the repeating section of code n If the test is at the beginning of the loop, the type of loop is a pre-test loop n If the test is at the end of the loop, the type of loop is a posttest loop Programming Fundamentals Fixed count loop and variable condition loop n n n n In addition to where the condition is tested, repeating sections of code are also classified In a fixed count loop, the condition is used to keep track of how many repetitions have occurred In this kind of loops, a fixed number of repetitions are performed, at which point the repeating section of code is exited In many situations, the exact number of repetitions are not known in advance In such cases, a variable condition loop is used In a variable condition loop, the tested condition does not depend on a count being achieved, but rather on a variable that can change interactively with each pass through the loop When a specified value is encountered, regardless of how many iterations have occurred, repetitions stop Programming Fundamentals while loops The while statement is used for repeating a statement or series of statements as long as a given conditional expression is evaluated to true Enter the while statement false test the condition ? The syntax for the while statement: true Execute the statement (s) while( condition expression){ Exit the while statement statements; } Programming Fundamentals Example 5.2.1 // This program prints out the numbers from to 10 #include int main() { int count; count = 1; // initialize count while (count

Ngày đăng: 11/04/2023, 16:03

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN