0

Look this sample Php code, what it is the output? It's allowed? I try to do the same in Java. It's too strict. Who is right?

https://code.sololearn.com/wA9b4YU0MOI4/?ref=app https://code.sololearn.com/cxxz7Hw2QdJ4/?ref=app

29th Apr 2017, 2:49 PM
Enrico Macchiavelli
Enrico Macchiavelli - avatar
4 Respuestas
+ 1
You have to put == for comparison instead of =, if you want to actually compare. if($a = $x) { \\ This is executed whenever the assignation is valid. }
29th Apr 2017, 2:54 PM
Bebida Roja
Bebida Roja - avatar
0
I prefer the Php approach. It evaluated all arguments and pass the result to if... Java expect a boolean expression/values, so don't allow you to make assignment in if. More formal, but LESS expressive and so long to write some rows of code!
29th Apr 2017, 2:54 PM
Enrico Macchiavelli
Enrico Macchiavelli - avatar
0
obviously in java I can't do the same..
29th Apr 2017, 2:55 PM
Enrico Macchiavelli
Enrico Macchiavelli - avatar
0
yes bebida, this is the purpouse of the code, and it works also if it's conceptually wrong!
29th Apr 2017, 2:58 PM
Enrico Macchiavelli
Enrico Macchiavelli - avatar