TAILIEUCHUNG - Học php, mysql và javascript - p 11

Example 4-31 shows a modified version of the multiplication table for 12 code using such a loop. Example 4-31. A loop for printing the times table for 12 "; while (++$count Notice how we are back to initializing $count to 1 (rather than 0), because the code is being executed immediately, without an opportunity to increment the variable. Other than that, though, the code looks pretty similar. Of course, if you have more than a single statement inside a loop, remember to use curly braces, as in Example 4-32. Example 4-32. Expanding Example 4-31 to use curly braces "; } while (++$count. | Example 4-31 shows a modified version of the multiplication table for 12 code using such a loop. Example 4-31. A loop for printing the times table for 12 php count 1 do echo count times 12 is . count 12 . br while count 12 Notice how we are back to initializing count to 1 rather than 0 because the code is being executed immediately without an opportunity to increment the variable. Other than that though the code looks pretty similar. Of course if you have more than a single statement inside a loop remember to use curly braces as in Example 4-32. Example 4-32. Expanding Example 4-31 to use curly braces php count 1 do echo count times 12 is . count 12 echo br while count 12 for Loops The final kind of loop statement the for loop is also the most powerful as it combines the abilities to set up variables as you enter the loop test for conditions while iterating loops and modify variables after each iteration. Example 4-33 shows how you could write the multiplication table program with a for loop. Example 4-33. Outputting the times table for 12 from a for loop php for count 1 count 12 count echo count times 12 is . count 12 . br See how the entire code has been reduced to a single for statement containing a single conditional statement Here s what is going on. Each for statement takes three parameters An initialization expression A condition expression Looping 81 A modification expression These are separated by semicolons like this for exprl expr2 expr3 . At the start of the first iteration of the loop the initialization expression is executed. In the case of the times table code count is initialized to the value 1. Then each time round the loop the condition expression in this case count 12 is tested and the loop is entered only if the condition is TRUE. Finally at the end of each iteration the modification expression is executed. In the case of the times table code the variable count is incremented. All this structure neatly removes any requirement .

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.