If Statement

If Statement

sudheer_r
Not applicable
136 Views
1 Reply
Message 1 of 2

If Statement

sudheer_r
Not applicable

[ FlexSim 20.0.0 ]

Is there any difference between the below if statements

Whats the difference between this two

if (2&&4==2&&4) {
	/*Statements*/
}
if (2==2 &&4==4) {
	/*Statements*/
}
0 Likes
Accepted solutions (1)
137 Views
1 Reply
Reply (1)
Message 2 of 2

Matthew_Gillespie
Autodesk
Autodesk
Accepted solution

They're very different.

2==2 && 4==4

This is comparing the two values on the left and the two values on the right and then ANDs the results together. So this statement is only true if both values on the left are the same and both values on the right are the same.

2 && 4==2 && 4

Because of the order of operations this will compare the two values in the middle first. If this is false then the whole statement is false. Otherwise it will AND that value with the values on the far left and right. If both of those are also true then the whole statement will be true.



Matthew Gillespie
FlexSim Software Developer