TAILIEUCHUNG - C++ Weekend Crash Course phần 3

Đầu tiên, điều kiện m n được đánh giá. Nếu kết quả là đúng, sau đó kiểm soát và chuyển cho các hướng dẫn sau {. Nếu m không lớn hơn n, sau đó kiểm soát vượt qua cú đúp ngay lập tức theo các điều khoản khác. Các điều khoản khác là tùy chọn. | 86 Saturday Morning The Branch Command The simplest form of flow control is the branch statement. This instruction enables the computer to decide which path to take through C instructions based on some logic condition. In C the branch statement is implemented using the if statement if m n instructions to be executed if m is greater than n else .instructions to be executed if not First the condition m n is evaluated. If the result is true then control passes to the instructions following the . If m is not greater than n then control passes to the brace immediately following the else clause. The else clause is optional. If it is not present C acts as if it is present but empty. Actually the braces are optional if there is only one statement to be executed as part of the while loop however it is too easy to make a mistake that the C compiler can t catch without the braces as a guide marker. It is much safer to always include the braces. If your friends try to entice you into not using braces just say NO. The following program demonstrates the if statement. BranchDemo - input two numbers. Go down one path of the program if the first argument is greater than the second or the other path if not include include int main int nArg char pszArgs input the first argument. Session 8 Flow Control Commands 87 int nArgl cout Enter argl cin nArgl .and the second int nArg2 cout Enter arg2 cin nArg2 now decide what to do if nArg1 nArg2 cout argument 1 is greater than argument 2 n else cout argument 1 is not greater than argument 2 n return 0 Here the program reads to integers from the keyboard and branches accordingly. This program generates the following typical results Enter arg1 10 Enter arg2 8 argument 1 is greater than argument 2 Part II-Saturday Morning Session 8 Looping Commands Branch statements enable you to control flow of a program s execution down one path of a program or another. This is the C equivalent of allowing the computerized mechanic to decide

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.