reading-notes

View the Project on GitHub Abu-laban/reading-notes

Comparison and Logical Operators

Comparison Operators

Operator Description
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type
> greater than
< less than
>= greater than or equal to
<= less than or equal to

** How Can it be Used **

Comparison operators can be used in conditional statements to compare values and take action depending on the result

Logical Operators

  1. && - and

    true && true returns true true && false returns false false && true returns false false && false returns false

  2.   - or  
    > true   true returns true
    > true   false returns true
    > false   true returns true
    > false   false returns false
  3. ! - not

    !true returns false !false returns true

Loops

** Loops are handy, if you want to run the same code over and over again, each time with a different value.**

  1. for - loops through a block of code a number of times

The for loop if you need to run a code a specific number of time.

  1. while - loops through a block of code while a specified condition is true

The while loop loops through a block of code as long as a specified condition is true.

  1. do/while - also loops through a block of code while a specified condition is true

The do/while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true.