English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

Like in any other language (syntacticly like C) , it loops an index from m to n.
The syntax is:
for (i=m; i < n; i++ ) {
// loop body to execute
}
for example, printing the numbers from 0 to 99:

for (i=0; i<100;i++) {
System.out.println ("i = " + i);
}

2007-05-25 19:15:33 · answer #1 · answered by atzipory 2 · 0 0

A loop is a common construct in most programming languages.
The for loop gives you the extra element of a built in incrementing variable.
Of course you can do this yourself with one of the other loop constructs but it is all there for you.

The power of the for loop is when united with an array.
The for loop gives you the ability to go through every element of an array and perform the same action on each element.

Of course this is not the only use of the for loop. The future is now open for you to discover.

2007-05-26 02:23:33 · answer #2 · answered by AnalProgrammer 7 · 0 0

for ... is a given fact/assuption... (for x !=5, ++1) says that as long as the value of x is not equal to a value of 5, increase the value by 1.
So as long as tha value is not 5, 1 will be added, and the loop will continue to the next arguement. When x does equal 5, this for loop will be considered closed and will be skipped.

2007-05-26 02:14:23 · answer #3 · answered by GeminiiMan 2 · 0 0

fedest.com, questions and answers