**Balfour**BSc

Jamie **Balfour** BSc

Full stack developer

An operator is similar to a mathematical or boolean operator. Operators can be used for arithmetic (mathematical operator) or for comparison (boolean operator).

There are a collection of mathematical operators that perform different tasks. The expressions used to represent such operators are shown in the following table, along with an example of each.

Name | Description | Operator Code | Example | Result |
---|---|---|---|---|

Addition | Simply used to add two numbers together. | `+` |
`5 + 10` |
15 |

Subtract | Used to subtract the second number from the first | `-` |
`10 - 5` |
5 |

Multiply | Used to multiply two numbers | `*` |
`7 * 4` |
28 |

Divide | Used to divide the first number by the second number and return a floating point number | `/` |
`50 / 7` |
7.14... |

Used to divide the first number by the second number and return an integer result | `\` |
`50 / 7` |
7 | |

Raise | Raise a number to another number in the same way as
the mathematical representation x^{y} |
`^` |
`2^7` |
128 |

Modulus | Used to get the remainder of a division as an integer. | `mod` |
`5 mod 4` |
1 |

These operators can be used to return a result as an integer or floating point number.

A boolean operator can be used to return a boolean value (True or False). The table below specifies all of these available in VB.NET:

Name | Description | Operator Code | Example (of truth) |
---|---|---|---|

Greater than | True if the first expression is greater than the second expression | > | 7 > 4 |

Less than | True if the first expression is less than the second expression | < | 7 < 16 |

Greater than or equal to | True if the first expression is greater than or equal to the second expression | >= | 17 >= 16 |

Less than or equal to | True if the first expression is less than or equal to the second expression | <= | 16 <= 16 |

Equal to | True if both expressions are equal (in VB.NET this works also for strings) | = | 16 = 16 |

Not equal | True if both expressions are not equal (again, works with strings in VB.NET) | <> | 16 <> 7 |

The results of these operations can be placed in a boolean variable as shown in the following sample:

VB.NET

Dim a As Integer = 5 Dim b As Integer = 9 Dim c As Integer c = a + b - 7 Dim result As Boolean result = c > a MsgBox(result)

The above sample should return True through the use of a message box.

Boolean logic also uses other operators. These can also be represented in VB.NET and are also known as bitwise operators. Formal logic and specification defines the way these work and VB.NET contains expressions that form statements like the following can be constructed in VB.NET:

x = (a ∧ b) ⊕ (c ∨ d)

The above expression will evaluate true when *a* and *b* are both false and either *c* or *d *are
true or when *a* and *b* are both true and both *c* and *d* are false due to the ⊕ operator.

The following table shows these operators.

Name | Description | Logical symbol | Operator code | Example (of truth) |
---|---|---|---|---|

And | Logical conjunction, true when both expressions are true. |
∧ | `And` |
`True And True` |

Or | Logical disjunction, true when either expressions are true. |
∨ | `Or` |
`True Or False` |

Not | Logical negation, returns true when given a false expression. |
¬ | `Not` |
`Not(False)` |

Exclusive or | Returns true when either expression is true, but not when both are true. |
⊕ | `Xor` |
`True Xor False` |

And also | Short-circuit logical and, true when both expressions are true. |
∧ | `AndAlso` |
`True AndAlso True` |

Or else | Short-circuit logical or, true when either expression is true. |
∨ | `OrElse` |
`True OrElse False` |

The following is a truth table that represents each of the operators shown above for some P and some Q.

P | Q | ¬P | P∧Q | P∨Q | P⊕Q | P AndAlso Q | P OrElse Q |
---|---|---|---|---|---|---|---|

T | T | F | T | T | F | T | T |

T | F | F | F | T | T | F | T |

F | T | T | F | T | T | F | T |

F | F | T | F | F | F | F | F |

Short-circuit logic is logic which saves time. Basically, the `AndAlso`

and `OrElse`

operators work exactly
like the And and the Or operators, but the difference is that they
follow a system where the code breaks when the first expression
to evaluate false (for `AndAlso`

) or true (for ` OrElse`

) occurs. This is shown here:

True And False And True And True And True

This will return False, as shown by the second expression - but
the program will check every expression anyway. With `AndAlso`

it will get to the first False expression (the second expression)
and return False.

The opposite happens with `OrElse`

. The following
example shows this:

False Or True Or True Or False Or False

This will return True, as shown by the second expression - but
the program will check every expression anyway. With `OrElse`

it will get to the first True expression (the second expression)
and return True.

They are very easy way to save system resources.

Welcome!

Welcome to my website. My name is Jamie Balfour and I'm
a computer scientist. My website focuses on me but also has
tutorials designed to help you learn things I know.

Current projects

- Dash CMS
- Consultancy website (more on release)
- Golf website (more on release)
- Sleep website (more on release)
- Zenith Engine v1.6.1
- Zenith Engine v2.0

@jamiebalfour04

#Top10SwitchGames:
1. Zelda BotW
2. Mario Odyssey
3. Skyrim
4. Fast RMX
5. PuyoPoyo Tetris
6. Fire Emblem Warriors… https://t.co/PhBtZx0X5I 6 days ago |

Retweet @ScotGovFM: Local Hero. First Minister @NicolaSturgeon meets @charmaine6173 and apprentices @on_lothianbuses at start of #ScotAppWeek18…2 weeks ago |

Retweet @EastCoastBuses: Good news
Our service 113 running its full route.
Please share https://t.co/G3vDy83gBl2 weeks ago |

What's the most desired thing for CSS? For me, it's better cross-platform print support such as footers. #BetterWeb 2 weeks ago |

@EastCoastBuses No wonder you're not coming to Pencaitland. It's pretty bad here! 3 weeks ago |

Get in touch