Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Concatenating an `if` statement

Why can't I just add || ("Jerk") instead of noun.equalsIgnoreCase("Jerk") to an existing identical code

1 Answer

andren
andren
28,558 Points

Because that's simply not how the language works. When you use || java will look at the two conditions on either side of it to see if either of them are true, it does not take the command on the left into account when it looks on the right, the conditions are considered entirely independent so chaining conditions is not possible in the way you demonstrate. Each condition needs to be a complete condition that would have been valid if it was used on it's own.

You could certainly argue that such a feature would be useful, but as it stands it's not a feature in the language, and a such it will just result in your code crashing if you attempted to do it.