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.