Analysis of the execution process of a for loop in Java _java

Source: Internet
Author: User

This article analyzes the execution process of the For loop in Java. Share to everyone for your reference. The specific analysis is as follows:

public class test01{public
static void Main (string[] args) { 
  int i = 0;
  For (foo (' A '); foo (' B ') &&i<3;foo (' C ')) {
  i++;
  Foo (' D ');
  }
public static Boolean foo (char c) {
System.out.print (c + "");
return true;
}

What is the result of this program output?
Yes, yes: a b d c b d c b d c b

Why is that so? Because the For loop executes the first semicolon before the ' a ', executes ' B ', and then executes the code in the For loop when it meets the criteria
Then jump to the second semicolon after the ' C ' this execution, and then compare ' B ' to meet the conditions, if satisfied then continue into the for loop
That is, the BDC continues to loop until the next condition is not satisfied until B is run, and the last ' B ' is output.

See here, do you have a deep understanding of the For loop?

I hope this article will help you with your Java programming.

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.