Struggling with ==

Started by
11 comments, last by luca-deltodesco 11 years, 9 months ago

It should be obvious if you rewrite it like this:
[source]
if(((a == b) == c) == d)
[/source]

also:
[source]
if(a == b)
{
if(1== c)
{
if(1== d)
{
...
}
}
}
[/source]
Advertisement

[quote name='Brother Bob' timestamp='1341944190' post='4957699']
It should be obvious if you rewrite it like this:
[source]
if(((a == b) == c) == d)
[/source]

also:
[source]
if(a == b)
{
if(1== c)
{
if(1== d)
{
...
}
}
}
[/source]
[/quote]

That's not right. If a=1, b=3, c=5, d=0 the original code would "do something", but your code would not.
if you 'really' wanted to expand (if (a == b == c == d)) into cascaded if's you'd have to write:

[source lang="java"]
if (a == b) {
if (1 == c) {
if (1 == d) {
...
}
}else if (0 == d) {
...
}
}else {
if (0 == c) {
if (1 == d) {
...
}
}else if (0 == d) {
...
}
}
[/source]

with each ... being replaced by the body of the origin if statement :P

This topic is closed to new replies.

Advertisement