We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
check point (Read 487 times)
check point
Jun 14th, 2007, 4:13pm
 
hi there,

I have an integer variable named s that I use it as index for the calling of an object stored within a Java Vector class named a. I then assign a random integer value restrained from the size of the Vector.

int s = int(random(-0.9,a.size()-0.1));

then I have another integer variable named n that is assigned to the return int value of a function that depends on one of the attributes of the object called.  

int n = nextype( ((Vec)availiable.elementAt(s)).b );

for some values of s the return value of the nextype function mean that the program should look for another object within the a Vector.

Is there a way to check for the value of n, and if I don't like it to re-execute the program from the int s random assignment?
Re: check point
Reply #1 - Jun 14th, 2007, 5:31pm
 
use a while loop:
http://processing.org/reference/while.html

Code:
boolean found = false;
while (!found) {
// grab random number
// .. code here ..

// check if it's good
if (randonNumber == good) {
found = true;
}
}


or do..while:

Code:
boolean found;
do {
// grab random number
// .. code here ..

// check if it's good
if (randonNumber == good) {
found = true;
}
} while (!found);
Re: check point
Reply #2 - Jun 20th, 2007, 5:42pm
 
thanks Smiley
Page Index Toggle Pages: 1