Skip to main content
Logo image

Section 2.3 Logical Values & Statements

Writing good code often means making decisions based on the values you are working with. For example, suppose gift_card_balance stores the amount of money on an Amazon gift card and total_due stores the price of a purchase. Before completing the purchase, your program needs to ask a yes-or-no question: β€œIs gift_card_balance greater than or equal to total_due?”
Questions like this are called logical statements, and their answers are called logical values. In MATLAB, logical values are the two special values true and false. In this section, we will learn how MATLAB represents these answers, how to build questions using relational operators, and how to combine and negate questions to express more complicated conditions.