question

SudheerReddy avatar image
0 Likes"
SudheerReddy asked Matthew Gillespie answered

If Statement

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*/
}
FlexSim 20.0.0
if loop
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Matthew Gillespie avatar image
4 Likes"
Matthew Gillespie answered

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.

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.