TAILIEUCHUNG - Writing do Statements

Viết làm Báo cáo này trong khi báo cáo và cho thử nghiệm cả hai biểu thức Boolean của họ tại đầu của vòng lặp. Điều này có nghĩa rằng nếu biểu thức để đánh giá sai lệch về các bài kiểm tra đầu tiên, cơ thể của vòng lặp không chạy, thậm chí không một lần. | Writing do Statements The while and for statements both test their Boolean expression at the start of the loop. This means that if the expression evaluates to false on the very first test the body of the loop does not run not even once. The do statement is different its Boolean expression is evaluated after each iteration and so the body always executes at least once. The syntax of the do statement is as follows don t forget the final semicolon do statement while booleanExpression Use a statement block if the body of the loop comprises more than one statement. Here s a version of the previous example that writes the values 0 through 9 to the console this time using a do statement int i 0 do i i while i 10 The break and continue Statements In Chapter 4 you saw the break statement being used to jump out of a switch statement. You can also use a break statement to jump out of the body of an iteration statement. When you break out of a loop the loop exits immediately and execution continues at the first statement after the loop. Neither the update nor the continuation condition of the loop is re-run. In contrast the continue statement causes the program to immediately perform the next iteration of the loop after re-evaluating the Boolean expression . Here s a version of the previous example that writes the values 0 through 9 to the console this time using break and continue statements int i 0 while true continue i i if i 10 continue else break This code is absolutely ghastly. Many programming guidelines recommend using continue cautiously or not at all because it is often associated with hard-to-understand code. The behavior of continue is also quite subtle. For example if you execute a continue statement from inside a for statement the update part runs before performing the next iteration of the loop. In the following exercise you will write a do statement to convert a number to its string representation. Write a do statement 1. .

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.