PHP 5/MySQL Programming- P19

PHP 5/MySQL Programming- P19:computer programming has often been seen as a difficult and arcane skill. Programming languages are difficult and complicated, out of the typical person’s reach. However, the advent of the World Wide Web has changed that to some extent. It’s reasonably easy to build and post a Web page for the entire world to see. The language of the Web is reasonably simple, and numerous applications are available to assist in the preparation of static pages | 68 PHP 5 MySQL Programming for the Absolute Beginner else if roll 6 binValue 110 else print I don t know that one. end if print br print img src print br print In binary print br print br print br br die that s binValue Refresh this page in the browser to roll another die. body html Using Multiple else if Clauses The Binary Dice program has only one if structure but that structure has multiple else clauses. The first condition simply checks to see if roll is equal to 1. If it is the appropriate code runs assigning the binary representation of 1 to the binValue variable. If the first condition is false the program looks at all the successive if else clauses until it finds a condition that evaluates to TRUE. If none of the conditions are true the code in the else clause is executed. You may be surprised that I even put an else clause in this code. Since you know the value of roll must be between 1 and 6 and you checked each of those values the program should never need to evaluate the else clause. Things in programming don t always work out the way you expect so it s a great idea to have some code in an else clause even if you don t expect to ever need it. It s much better to get a message from your program explaining that something unexpected occurred than to have your program blow up inexplicably while your users are using it. The indentation for a multiple-condition if statement is useful so you can tell which parts of the code are part of the if structure and which parts are meant to be executed if a particular condition turns out to be true. 69 Using the switch Structure to Simplify Programming The situation in the Binary Dice program happens often enough that another structure is designed for when you are comparing one variable to a number of possible values. The Switch Dice program in Figure looks identical to the Binary Dice program as far as the user is concerned except Switch Dice shows the roll s Roman numeral representation. FIGURE This .

Không thể tạo bản xem trước, hãy bấm tải xuố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.