Condition statements

Control flow tools include the if statement, for and while loops. They control the flow of the program.

All control flow tools involve evaluating a condition statement. The program will proceed differently depending on whether a condition is met.

The most common condition statement is the comparison statement. If we want to compare whether two variables are the same, we use the == sign. For example, if we we write x == y, the program is asked to check if x is equal to y. If they are equal, the condition is met and will be considered True. Else, it will be considered False.

Other comparison signs include:

not equals (!=)

greater than (>)

less than (<)

greater than or equals to (>=)

less than or equals to (<=)

There are also three logical operators. They include and, or and not and are useful to combine multiple conditions.

The and operator gives True if all conditions are met, otherwise False.

The or operator gives True if at least one condition is met, otherwise False.

The not operator gives True if the condition after the not keyword is false, otherwise False.

No comments:

Post a Comment