A for loop is usually written as
for(i =0; i<10; i++)
However, instead of i++ I want to go up in increments of 20000, and my program wont compile when I write i + 20000, does anyone know how you do this??
Thanks very much!
I haven't used this in Java, but it is valid in C. In C, you can use any valid expression to alter the value of i. I would think that the same is true in Java.
In your example i + 20000 doesn't change i whereas i+=20000 or i = i + 20000 do.
Originally posted by kateryan13 A for loop is usually written as
for(i =0; i<10; i++)
However, instead of i++ I want to go up in increments of 20000, and my program wont compile when I write i + 20000, does anyone know how you do this??
Thanks very much!
PHP Code:
public class ForCounter
{
public static void main(final String[] args)
{
for (int i = 0; i < 1000000; i++)
{
i+=20000;
System.out.println(i);
}
}
}
Like this? There's a problem. It keeps summing "i" every iteration by 1.
Hrmm..
Kind regards,
Jaime Bueza
Last edited by BuezaWebDev; 11-29-2004 at 06:41 PM.
Bookmarks