TAILIEUCHUNG - Computer Programming for Teens phần 4

Ngoài các loại, chúng tôi đã nghiên cứu các số nguyên, tăng gấp đôi, nhân vật, và chuỗi các loại, có một dạng khác, boolean, được đặt tên theo nhà toán học George Boole, người đã làm việc trong chủ đề của logic. Nó là một loại biến chứa kết quả đúng hay sai. | 86 Chapter 6 True or False The Basis for All Decisions The Boolean Type In addition to the types we have already studied the integer double character and string types there is another type the boolean named after the mathematician George Boole who did extensive work in the subject of logic. It is a variable type that holds the result true or false. These values are not the strings true or false. They are the values true or false. The only way to get these values is to use the relational operators etc. and or the logic operators and or not from Chapter 3. When you compare two numbers with a relational operator you get a value of true or false. Example Result 16 15 True False -12 4 True Now let s declare some boolean variables and use them in assignment statements with these examples. Because we want to declare more than one boolean variable at once we will make a list of variables after the type boolean. Just separate the variables by commas before ending the declaration statement with the semicolon. Let s use the name flag for one of the boolean variables since flag reminds us of the expression to raise a flag and catches our attention. You will later see why this is useful. variable type variable variable etc. boolean flag x answer flag x and answer are all boolean type variables Example Result flag 16 15 x answer -12 4 flag holds true x holds false answer holds true Now let s consider some examples where the boolean type is used with some variables in relational expressions. In the previous examples the values were used directly in the relational expressions. What Does a Decision Involve 87 int a b c declaring three integers in a list boolean answer flag result declaring three booleans a 14 b 0 c 7 Example Result answer a c answer holds false because 14 is not less than 7 14 7 flag b c flag holds false because 0 is not greater than 7 0 7 result a b result holds true because 14 is greater than 0 14 0 Tip When you want to declare more than one .

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.