Hi all.
I hope you can understand my poor english...
I've two for cycles nested
for (vector1, index i)
for (vector2, index j)
myObject o = new myObject(vector1.elementAt(i),
vector2.elementAt(j))
The problem is that the order of the nested cycles depends of a param.
I could use something like
if (param == true)
x = vector1
y = vector2
else
x = vector2
y = vector1
for (x, index i)
for (y, index j)
if (param == true)
myObject o = new myObject(x.elementAt(i), y.elementAt(j))
else
myObject o = new myObject(y.elementAt(i), x.elementAt(j))
but is there a standard or better method to do this?
Thanks all!
DM
Venky - 17 Jan 2006 09:21 GMT
I think the solution which you have mentioned is good if you remove the
if condition in the for block as you have already taken care of it
outside the for block.
Anyways, You can do this in two ways
1)
if (param == true) {
x = vector1
y = vector2
}else {
x = vector2
y = vector1
}
for (x, index i)
for (y, index j)
myObject o = new myObject(x.elementAt(i), y.elementAt(j))
2)
for (vector1, index i)
for (vector2, index j)
if (param == true)
myObject o = new myObject(vector1.elementAt(i),
vector2.elementAt(j))
else
myObject o = new myObject(vector2.elementAt(i),
vector1.elementAt(j))
I think first one is better because of less number of comparisions
(even though you are using two extra variables).
Denis - 17 Jan 2006 09:41 GMT
Not so good... when I create myObject, the param order is important!
Width your solution the param order change! :-)
DM
Venky - 17 Jan 2006 10:05 GMT
If the value of "param" variable doesn't change in the for loop, then
both the solutions which I have mentioned above will give the same
result as yours.