From the course: Computer Science Principles: Programming

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Build compound conditional tests

Build compound conditional tests

- Simple questions are easy to understand and program, but life is rarely simple. When you create conditional tests sometimes you need to ask multiple questions to get to the single true or false answer you need to proceed. In programming you can do exactly that with logical operators. If we have a single test, you will get a single true or false answer. This can be a literal value, a variable, an evaluation using equality operators or a function that returns a boolean value type. But if I have two tests, I need to find a way to get a single true or false answer. One possible question to ask is if A is true or if B is true, then it is true. This uses the or logical operator. It says that if either of the items are true, then the whole thing is true. With two tests there are four possible combinations. Three of which would evaluate as true, and one would be false. The only way this could be false is if both evaluations were false. The other possible question to ask is if A is true and…

Contents