Java loop statement Summary

Source: Internet
Author: User
Someone asked me a question.
String [] greeting = new string [3];
Greeting [0] = "Welcome to core Java ";
Greeting [1] = "by Cay horstmman ";
Greeting [2] = "and Oliver Lee ";
For (string G: greeting)
{
System. Out. println (g );
}
How is the for loop implemented here?
I have never seen it before. By the way, I will summarize the Java loop:
① The commonly used for loop is
For (initialization; condition; iteration ){
// Body
}
Example:
For (INT x = 0; x <100; X ++ ){
System. Out. println (X );
}

② Do... while (condition)
This method executes a loop at least once. First, it executes an operation until the condition is met.
For example, int sum = 0; int n = 1;
Do {sum + = n ++} while (N <= 100 );

③ While (condition)
This method performs loop operations only when the conditions are met.
Example: While (x <100)
{
Sum ++;
}
I don't know whether there are other writing methods, or the above syntax has other writing methods.

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.