5.8. Summary

We started this chapter with the selection statements if and switch and ternary constructs. We covered the different flavors of the if construct. Then we looked at the switch construct, which accepts a limited set of argument types including byte, char, short, int, and String. The humble if-else construct can define virtually any set of simple or complicated conditions.

You also saw how you can execute your code using all types of loops: for, for-each, do, and do-while. The for, do, and do-while loops have been around since the Java language was first introduced, whereas the enhanced for loop (the for-each loop) was added to the language as of Java version 5.0. I recommend that you use the for-each loop to iterate through arrays and collections.

At the end of this chapter, we looked at the break and continue statements. You use the break statement to exit—or break out of—a for, for-each, do, do-while, or switch construct. You use the continue statement to skip the remaining steps in the current iteration and start with the next loop iteration.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.173.238