dz63:
This is a pretty basic question. I believe that I have seen online examples of if statements with just a simple < or > operator, but never with just a simple = operator. Is the == operator always needed within an an expression found in the if statement? Hoping someone with more experience would be willing to share the reason.
"==" means "does it equal?"
"=" means "set this to that".
Example:
** X = 3;**
** if (X == 4) {**
** print ("It's not the same!"); <-- this gets printed because 3 is not equal to 4**
** } else {**
** print ("It matches!");**
** }**
Now watch what happens here:
** X = 3;**
** if (X = 4) { <-- this SETS X to a value of 4**
** print ("It's not the same!");**
** } else {**
** print ("It matches!"); <-- this gets printed because setting X to anything returns boolean "true"**
** }**
Make sense?