TAILIEUCHUNG - Professional C# Third Edition phần 10

Bây giờ chúng ta hãy thảo luận về các vòng lặp, được giới thiệu trong đoạn mã trước đó. Những gì chúng tôi có ở đây là C # tương đương với đoạn mã Visual Basic: Dim I As Integer Đối với I = 1 - 3 "Thông tin chi tiết của nhân viên" Next | Appendix B Simpo PDF Merge and Split Unregistered Version - http The for Loop Now let s discuss the for loop introduced in the previous code snippet. What we have here is the C equivalent of this Visual Basic code Dim I As Integer For I 1 To 3 Details of the Employee Next The idea of the For loop in Visual Basic is that you start off by initializing a variable called the loop control variable and each time you go round the loop you add something to the loop control variable until it exceeds a final value. This is quite useful but gives you almost no flexibility in how the loop works. Although you can change the value of the increment or even make the increment negative by using the Step facility the loop always works by counting and the test of whether the loop exits is always whether the variable has reached a preset minimum or maximum value. In C the for loop generalizes this concept. The basic idea of the for loop in C is this At the beginning of the loop you do something at each step of the loop you do something else in order to move to the next iteration and in order to determine when to exit from the loop you perform some test. The following table provides a comparison between the Visual Basic and C versions of this loop. Loop Visual Basic C At start of loop. Initialize the loop control variable. Do something. To test whether to exit loop. Check whether the loop control variable has reached a certain value. Test some condition. At end of each iteration. Increment the loop control variable. Do something. This might look a bit vague but it does give you a lot of flexibility For example in C instead of adding a quantity to the loop control variable at each iteration you might multiply its value by some number. Or instead of adding on a fixed amount you might add some number that you ve read in from a file and which changes with each iteration. The test doesn t have to be a test of the value of the loop control variable. It .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.