Talk about the understanding of nested for loops

Source: Internet
Author: User

Talk about the understanding of nested for loops

for nesting, let's talk about how A for loop is used.

The purpose of this is to use a for loop to output a multiplication table, which is my step-by-step understanding.

< Span style= "FONT-SIZE:14PT;" >    I.   syntax:
            for (expression 1; Expression 2; expression 3) {
                java statement;
            }
        
          Expression 1 is an initialization expression that executes first and executes only once.
         Expression 2 must be an expression of type Boolean.
        for loop starts execution, executes expression 1 first, and executes only once.
         to determine the result of expression 2, and if true, executes the Java statement.
         re-executes expression 3, based on the section of expression three, and then the result of expression 2 until expression 2
          The result is false, the For loop ends.

Two. To cite an example,

This results in the following output:

you will find it to be a line style.

So I'm nesting a for loop inside this for loop, and the code

To show the results of the output:

There is no discovery, nested A for inside, will be from a line to become a face, it will be better for people to understand.

My goal is to make a multiplication table, the basic format has been, the following is the change in the data inside, the data is multiplied, so I changed the output style

(The multiplication formula in no 0 ah, the inside of the 0 to change to 1, sorry, silly, unexpectedly from 0 began to count multiplication formulas, the following change over AH)

The output is:

Basic is finished, so to modify the "J" value is OK, the code

After this modification, the appearance is:

Such a multiplication table is called out, in fact, for the nesting can be considered as a line into a polygon process.

It's easy to understand the principles. Continue next week.

Talk about the understanding of nested for loops

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.