What is the difference between & and && operator, Please provide an example for it | Selenium Forum
R
Romit Posted on 23/07/2019

A
Ashish Thakur Replied on 24/07/2019

& will check both the conditions even if the first one is false. Whereas,

&& will not check the second condition of the first one is false


R
Romit Replied on 10/07/2020

If & will check both the conditions than what will be the output if first condition is true and second is flase.
and if the output will be false than what is the purpose of using it over && operator.


A
Ashish Thakur Replied on 12/07/2020

(1==2) & (1==1) -> out put is false. Both conditions are evaluated

(1==1) & (3==3) -> out put is true. Both conditions are evaluated

(1==2) && (1==1) -> out put is false. Both conditions are evaluated

(1==2) && (3==3) -> out put is true. 1==2 is false. So it does not goes to 3==3 since one condition is false.. result will obviously be false


R
Romit Replied on 12/01/2021

I believw it should be as folows:

(1==2) & (1==1) -> out put is false. Both conditions are evaluated

(1==1) & (3==3) -> out put is true. Both conditions are evaluated

(1==2) && (1==1) -> out put is false. First(not both) condition is evaluated

(1==2) && (3==3) -> out put is false(not true). 1==2 is false. So it does not goes to 3==3 since one condition is false.. result will obviously be false

Am i right?


Related Posts