Shaine
0
Q:

java loop

for(int i = 0; i < 10; i++)
{
  //do something
  
  //NOTE: the integer name does not need to be i, and the loop
  //doesn't need to start at 0. In addition, the 10 can be replaced
  //with any value. In this case, the loop will run 10 times.
  //Finally, the incrementation of i can be any value, in this case,
  //i increments by one. To increment by 2, for example, you would
  //use "i += 2", or "i = i+2"
}
18
int values[] = {1,2,3,4};
for(int i = 0; i < values.length; i++)
{
 	System.out.println(values[i]); 
}
18
for (int i = 0; i < 10; i++) {
  System.out.println(i);
}
12
//Main two types of loops:
//For loop:
for(/*index declaration*/int i=0; /*runs as long as this is true*/
   i<=5; /*change number at end of loop*/i++){
doStuff();

}
//While loop:
//runs as long as the condition is true
while(condition){
//do what you want in here
doStuff()
}
4
// Will continue until condition is true
while (condition) {
  // Code block to be executed
}

// Will loop trough until i = 5 
int i = 0;
while (i < 5) {
  System.out.println(i);
  i++;
}
5
for (type variableName : arrayName) {
  // code block to be executed
}
3
class for_loop
{
	public static void main(String args[])
    {
     	for(int i=0;i<10;i++)
        {
          System.out.print(" " + i);
        }
      /*
      Output: 0 1 2 3 4 5 6 7 8 9 
      */
    }
}
0

New to Communities?

Join the community