When to use And, AndAlso and Or, OrElse? [duplicate]

2

I do not know when to use the syntaxes Or or OrElse and / or And or AndAlso , because I do not understand what difference it makes in the logic circuit.

Being in C #, And = & , AndAlso = && and Or = | , OrElse = || .

I need to test the following expression to know if the integer lastToken is zero (0) and also if it is greater than 2:

if(lastToken == 0 & lastToken > 2) { ... }

But I do not know if I use & or && .

Which one should I use?

    
asked by anonymous 24.09.2017 / 20:05

1 answer

2

Good afternoon.

& and & are the same comparisons, however:

If you have a Expression1 & Expression2 , he will check both, soon you will spend more time.

If you have Expression1 & Expression2 , it will check the first and will only check the second if the first one is true .

If you are studying, use any one, but there will come a time that the speed of your code will influence.

Or and OrElse follows the same logic.

    
24.09.2017 / 20:16