TAILIEUCHUNG - Programming in Objective-C 2.0 edition phần 3

Các ví dụ trước đó sử dụng một năm đó không phải là một năm nhuận bởi vì nó không phải là chia hết cho 4 (1955), một năm đó là năm nhuận bởi vì nó là chia hết cho 400 (2000), và một năm đó không phải là một bước nhảy vọt năm bởi vì nó là chia hết cho 100 nhưng không 400 (1800). | The if Statement 109 Program Output Rerun Enter the year to be tested 2000 It s a leap year. Program Output Rerun Enter the year to be tested 1800 Nope it s not a leap year. The previous examples use a year that is not a leap year because it isn t evenly divisible by 4 1955 a year that is a leap year because it is evenly divisible by 400 2000 and a year that isn t a leap year because it is evenly divisible by 100 but not by 400 1800 .To complete the run of test cases you should also try a year that is evenly divisible by 4 and not by is left as an exercise for you. We mentioned that Objective-C gives the programmer a tremendous amount of flexibility in forming expressions. For instance in the previous program you did not have to calculate the intermediate results rem_4 rem_100 and rem_400 you could have performed the calculation directly inside the if statement as follows if year 4 0 year 100 0 year 400 0 Using blank spaces to set off the various operators still makes the previous expression readable. If you decided to ignore this and removed the unnecessary set of parentheses you could end up with an expression that looked like this if year 4 0 year 100 0 year 400 0 This expression is perfectly valid and believe it or not executes identically to the expression shown immediately before it. Obviously those extra blanks go a long way toward aiding our understanding of complex expressions. Nested if Statements In discussions of the general format of the if statement we indicated that if the result of evaluating the expression inside the parentheses is TRUE the statement that immediately follows is executed. It is perfectly valid for this program statement to be another if statement as in the following statement if chessGame isOver NO if chessGame whoseTurn YOU chessGame yourMove If the value returned by sending the isOver message to chessGame is NO the following statement is executed this statement in turn is another if if statement .

TỪ KHÓA LIÊN QUAN
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.