0
If I did change the == into a = in an if statement will it change the value of the of the variable
9 Respuestas
0
yes it will change the value of variable
and make your if statement always true
and it will be executed every time
and in case of loop sometime it goes into infinite loop also
+ 5
@Karl I think I meant to say that = can be used in if conditional statements without producing compilation errors, not literally = being ==. I'll just leave my original post there as a monument to my derpyness. :>
+ 5
int main() {
int a=7;
if (a=1){a++;}
cout<<a; //outputs 2
}
Same for C++
It does not result in an error.
If a is assigned 0 in the condition block, the statements in {} wont run. The statements run for all other values of a.
+ 4
Hatsy- you sure about that? I think JS considers = as a =, not ==.
+ 4
@Hatsy- Ok gotcha. =)
+ 3
IIRC, JS is tolerant towards the use of = in if statements, and will evaluate it as a == (?). For C++ and Java, this should result in a compilation error.
+ 1
yes value will be changed and if block will be executed if value is not false
a = 5;
if(a = 7){
alert('true');
}
alert(a);
this will show alert "true" and alert "7"
0
no @vaibhav it will not be executed everytime, it depends on values try this
a = 5;
if(a = false){
alert('true');
}
alert(a);
0
Thank you