Read05
Operators
Comparison operators:
You can evaluate a situation by comparing one value in the script to what you expect it to be, and the result will always be boolean.
- You can use several tools to compare values such as:
1- (==) “is equal to”, the operator compares if two values if they are the same.
2- (!=) “is not equal to”, the operator compares the two values if they are not the same.
3- (===) “is strict equal to”, the operator compares the two values if the values and the datatype are the same.
4- (!==) “is strict not equal to”, the operator compares the two values if the values and the datatype are not the same.
5- (<) “is less than”, the operator compares if the number on the left is less than the one on the right.
6- (>) “is greater than”, the operator compares if the number on the left is greater than the one on the right.
7- (<=) “is less than or equal”, the operator compares if the number on the left is less thaan or equal the one on the right.
8- (>=) “is greater than or equal”, the operator compares if the number on the left is greater than or equal the one on the right.
Llogical operators:
Comparison operators usually return single values, logical operators allowes you to compare the results of the comparison operators.
- You can use several logical operators to compare such as:
1- (&&) “logical And”, this operator tastes more than one condition, and to have “True” as your result all conditions must be true.
| 2- ( | ) “logical Or”, this operator tastes more than one condition, and to have “True” as your result atleast one conditions must be true. |
3- (!) “logical not”, this operator takes the boolean and inverts it.
Loops
Loops check a condition, it returns true a code block will run, then the condition will be checked again and if it still return true the code block will run again, it repeates until the condition returns false.
- There are several types of loops such as:
1- For loop: it is used to run a code specific number of times, the condition is usually a counter which is used to tell how many times the loop should run.
A for loop is consisted of three parts which is:
-
Initialization: create a vaariable and sit it at a starting point it is usually referred to as “i”.
-
Condition: the loop should continue to run until the counter reaches a specified number.
-
Update: every time the loop has run there is an updat on the variable.
2- While loop: if you don’t know how many times you should run the loop a while loop is the best to use.