C for Dummies 2nd edition phần 6

Nó không phải là phá vỡ, không sửa chữa nó. Nếu Doug không hỏi tôi đến vũ hội, tôi sẽ phải đi với Charley. Tất cả những ví dụ cho thấy các quyết định quan trọng, tương tự như những người bạn có thể thực hiện trong chương trình C của bạn bằng cách sử dụng từ khóa nếu. | 190 Part III Giving Your Programs the Ability to Run Amok Tearing through step at a time I admit that the for l oop isn t the easiest of C s looping instructions to understand. The problem is all the pieces. It would be easier to say for example for 6 statements and then repeat the stuff between the curly braces six times. But what that does is limit the power of the for command s configuration. To help you better understand how for s three parentheses pieces parts make sense I use the following for statement from as an example for i 0 i 5 i i 1 The for l oop uses the variable i to count the number of times it repeats its statements. The first item tells the for l oop where to begin. In this line that s done by setting the integer variable i equal to 0. This plain old C language statement stuffs a variable with a value i 0 The value 0 slides through the parentheses into the integer variable i. No big deal. The second item is a condition like you would find in an if statement that tells the for l oop how long to keep going to keep repeating itself over and over as long as the condition that s specified is true. In the preceding code as long as the statement i 5 the value of the variable i is less than 5 is true the loop continues repeating. It s the same as the following if statement if i 5 If the value of variable i is less than 5 keep going. The final item tells the for l oop what to do each time it repeats. Without this item the loop would repeat forever i is equal to 0 and the loop is repeated as long as i 5 the value of i is less than 5 . That condition is true so for would go on endlessly like a federal farm subsidy. However the last item tells for to increment the value of the i variable each time it loops i i 1 Chapter 15 C You Again 191 The compiler takes the value of the variable i and adds 1 to it each time the for l oop is run through once. Refer to Chapter 11 for more info on the art of incrementation. Altogether the for l oop works out .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.