r/learnjava • • Aug 08 '18

Making code make decisions ...

Control flow is central to making decisions in Java. Mastering control flow makes it possible to make decisions with code ...after all that’s why we write code:

making decisions with Java

2 Upvotes

1 comment sorted by

9

u/desrtfx Aug 08 '18

The brackets are actually optional

In the example above, we can optionally omit the brackets {}. This generally isn't advised as it makes code less readable and becomes necessary with more complex logic like if..then..else

This is not entirely correct and dangerous advice.

Should be:

The brackets are actually optional for single line blocks

You should really emphasize that this is considered bad practice and actually against the Official Oracle Code Conventions for the Java Programming Language (section 7.4) and the Google Java Style (section 4.1.1)


Using for with arrays

This is called enhanced for. You need to make clear that this way is read only! The elements in the array cannot be changed with an enhanced for loop.


labeled break

Please, please make it clear that this should not really be used! Labeled breaks are the new goto. They commonly are a huge code smell and debugging hell.


Other than the above, this time you managed to get a somewhat decent tutorial together. You're improving.