09-28-2012, 06:49 AM | #21 | |
Spun a twirly fruitcake,
Join Date: Feb 2009
Age: 31
Posts: 3,865
|
Re: Continuin to fail at Java
New problem:
Is there a way to make a for-loop that repeats its previous steps when the increment increases. i.e: Code:
public void recurseLoop(int condition){ for(int x = 0; x < condition; x++){ //when x=0 it does a command //when x=1 it does the previous command and another command //when x=2 it does the previous 2 commands and another command //when x=3 it does the previous 3 commands and another command //etc } } But in some cases the program replaces a value in the ArrayList, hence why it has to keep doing the previous commands. Any ideas?
__________________
Quote:
Last edited by SKG_Scintill; 09-28-2012 at 06:52 AM.. |
|
09-28-2012, 09:53 AM | #22 |
Woof
Join Date: Jan 2006
Location: MA
Posts: 173
|
Re: Continuin to fail at Java
Do you mean something like this?
Code:
for (int x = 0; x < condition; x++) { for (int y = 0; y < x; y ++) { System.out.println(y); } } // For x = 3, prints out 0, 0, 1, 0, 1, 2 Last edited by powerfull; 09-28-2012 at 11:22 AM.. |
09-29-2012, 05:08 AM | #23 |
FFR Veteran
|
Re: Continuin to fail at Java
To do something like this
Code:
public void recurseLoop(int condition){ for(int x = 0; x < condition; x++){ //when x=0 it does a command //when x=1 it does the previous command and another command //when x=2 it does the previous 2 commands and another command //when x=3 it does the previous 3 commands and another command //etc } } Code:
public void recurseLoop(int condition){ for(int x = 0; x < condition; x++){ switch(x){ case 3: command3(); case 2: command2(); case 1: command1(); case 0: command0(); } } } |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|