Decisions and Loops

Evaluating condition

You can evaluate a situation by comparing one value in the script to what ypu expect it might be. The resuklt will be a Boolean: true or false.

Examples

== (Is Equal to)

!= (Is not Equal to)

=== (Strict Equal to)

!== (Strict not Equal to)

> (Greater than)

< (Less than)

>-= (Greater than or Equal to)

<= (Less than or Equal to)

Logical operators

Comparison operators usually return single values of true or false. Logical operators allow you to compare the results of more than one comparison operator.

Examples:

&& (Logical and): This operator tests more than one condition.

II ( logical or): This operator tests at least one condition.

! (Logical not): this operator takes a single Boolean value and inverts it.

If statements

The if statement evaluates (or checks) a condation. If the condation evaluates to true, any statement in the subsequent code block are executed.

True ##If…Else statement

The If…else statement checks a condation. If resolves to true the first code block is executer. If the condation resolves to false the second code block is run instead.

if else

Switch statements

Switch

Loops

Loops checks a condition. If it returns, a code block will run. Then the condition will be checked again and if it still returns true, the code block will run again. It repeats until the condition returns false. There are three common types of loops:

1. FOR: If you need to run code a specific number of times,use a for loops.

2. While: If you not know how many times the code should run, you can use a while loop.

loops

Loop counters

A for loop uses a counter as a condition. This instructs the code to run a specified number of times.

counter