Go Back   Flash Flash Revolution > General Discussion > Technology

Reply
 
Thread Tools Display Modes
Old 09-28-2012, 06:49 AM   #21
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default 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
	}
}
I have an ArrayList and every element needs a different command.
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:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.

Last edited by SKG_Scintill; 09-28-2012 at 06:52 AM..
SKG_Scintill is offline   Reply With Quote
Old 09-28-2012, 09:53 AM   #22
powerfull
Woof
FFR Veteran
 
powerfull's Avatar
 
Join Date: Jan 2006
Location: MA
Posts: 173
Default 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
It goes through the for-loop condition-many times, then it'll go through another for-loop condition-many times with the current x-value as its limit every time. I hope that helps in some way.
__________________


Some music: http://soundcloud.com/wooffull

Last edited by powerfull; 09-28-2012 at 11:22 AM..
powerfull is offline   Reply With Quote
Old 09-29-2012, 05:08 AM   #23
UserNameGoesHere
FFR Veteran
FFR Veteran
 
UserNameGoesHere's Avatar
 
Join Date: May 2008
Posts: 1,114
Send a message via AIM to UserNameGoesHere
Default 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
	}
}
You do something like this
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();
		}
	}
}
Just a switch statement without breaks -- you rely on fallthrough behavior.
__________________
Quote:
Originally Posted by Crashfan3 View Post
Man, what would we do without bored rednecks?
[SIGPIC][/SIGPIC]
UserNameGoesHere is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 02:26 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution