Blocks

The code in Java is created in code blocks. Anything that is between the { and } characters is a block. In the preceding example, the code of the method is a block. It contains commands, and some of them, like the while loop, also contain a block. Inside that block, there are two commands. One of them is a for loop, again with a block. Although we can have single expressions to form the body of a loop, we usually use blocks. We will discuss loops in detail in just a few pages.

As we could see in the preceding example, the loops can be nested, and thus the { and } characters form pairs. A block can be inside another block, but two blocks cannot overlap. When the code contains a } character, it is closing the block that was opened last.

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

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