Expressions and operators

https://mrobeidat.github.io/reading-notes/


Expressions and operators

Expressions perform specific actions, based on an operator, with one or two operands. An operand can be a constant, a variable or a function result. Operators are arithmetic, logical, and relational. As with C, some operators vary in functionality according to the data type of the operands specified in the expression.

An operator excutes some operation on single or multiple operands and return with a results.

The types of operators are :

  1. Comparison Operators which are used in logical statements to determine equality or difference between variables or values. for ex : (< , > , = , !=, …)
  2. Assignment operators which are used to assign values to variables. for ex : ( += , =)
  3. Arithmetic operators which takes numerical values (either literals or variables)

Loops and iteration

Loops are used to perform a set of statements more than once until a the right condition is satisfied.

## In Java we have three types of basic loops:

  • While : Java while loop is using a boolean condition and it excuted repeatedly that will allows code to be executed a few times.

  • Do-while : This do-while loop is executed at least once because condition is checked after loop body.

  • For loop : a little bit the same as other loops but the difference are they typically used when the number of iterations is known before entering the loop.

Here are the flow chart for each one of them :

while loop:

While loop

Do-while loop :

Do While loop

For loop :

For loop