I've been trying to tackle a programming-problem,and have come across a scoping problem. Here is a SCE of the problem:
for (int Hole1 = 1; Hole1 < beavers; Hole1++) {
list = exampleList;
for (int t = 0; t < Hole1; t++) {
temp.add(list.get(0));
list.remove(0);
}
for (int p = 0; p < Hole1; p++) {
list.add(temp.get(temp.size() - 1));
temp.remove(temp.size() - 1);
}
exampleList2 = list;
for (int Hole2 = 1; Hole2 < beavers; Hole2++) {
list = exampleList2;
for (int t = 0; t < Hole2; t++) {
temp.add(list.get(0));
list.remove(0);
}
for (int p = 0; p < Hole2; p++) {
list.add(temp.get(temp.size() - 1));
temp.remove(temp.size() - 1);
}
exampleList3 = list;
for (int Hole3 = 1; Hole3 < beavers; Hole3++) {
list = exampleList3;
for (int t = 0; t < Hole3; t++) {
temp.add(list.get(0));
list.remove(0);
}
for (int p = 0; p < Hole3; p++) {
list.add(temp.get(temp.size() - 1));
temp.remove(temp.size() - 1);
}
System.out.println(list.toString() + " " + Hole1 + " " + Hole2 + " " + Hole3);
if (check(list))
System.out.println("match");
}
}
}
My problem is that examplelist3 changes value for every iteration of the hole3 for loop
, but from my understanding each loop
completes it's iterations before moving on. Anyone have an idea of what's going on?
EDIT* removed the SCE and posted the code instead