1for(int i = 0; i < 10; i++)
2{
3 //do something
4
5 //NOTE: the integer name does not need to be i, and the loop
6 //doesn't need to start at 0. In addition, the 10 can be replaced
7 //with any value. In this case, the loop will run 10 times.
8 //Finally, the incrementation of i can be any value, in this case,
9 //i increments by one. To increment by 2, for example, you would
10 //use "i += 2", or "i = i+2"
11}
1// Starting on 0:
2for(int i = 0; i < 5; i++) {
3 System.out.println(i + 1);
4}
5
6// Starting on 1:
7for(int i = 1; i <= 5; i++) {
8 System.out.println(i);
9}
10
11
12// Both for loops will iterate 5 times,
13// printing the numbers 1 - 5.
1//Main two types of loops:
2//For loop:
3for(/*index declaration*/int i=0; /*runs as long as this is true*/
4 i<=5; /*change number at end of loop*/i++){
5doStuff();
6
7}
8//While loop:
9//runs as long as the condition is true
10while(condition){
11//do what you want in here
12doStuff()
13}
1class for_loop
2{
3 public static void main(String args[])
4 {
5 for(int i=0;i<10;i++)
6 {
7 System.out.print(" " + i);
8 }
9 /*
10 Output: 0 1 2 3 4 5 6 7 8 9
11 */
12 }
13}
1for(int i = 0; i < 10; i++){
2 System.out.println(i);
3 //this will print out every number for 0 to 9.
4}
1public class name_of_java_app {
2public static void main(String[] args) {
3 int value = 4;
4 string whatever_value = "whatever_val";
5 // The value can be whatever you want.
6 for(int name_of_int; name_of_int < value; name_of_int++) {
7 System.out.println(whatever_value + name_of_int);
8 }
9 // The output will be 0 1 2 3 4 whatever_val
10 // You can put any data value such as char or short but not boolean
11}
12}