
Suzanne O. answered 02/22/22
International Experience and Multiple State Certifications
Hi Mike,
Those two, "=" and "==" can be confusing at times.
We are talking about C and it's myriad derivative languages (like Java....).
The symbol = is used to assign a value to a variable. When you are reading code, you say gets:
x=1 "ex gets one"
So when the code is executed, the value of x becomes 1.
The symbol == is used to test for a condition in logical expressions. I like to say when you see equals equals then the variable really does equal something. It returns a true or false answer.
Use == in combination with a logical expression to test the conditions:
if (x==42) { This little snippet would assign y the value of 2 ONLY when x was 42
y=2; If x is not 42, the value of y stays the same
}
Hope this helps.