Well, you may want to do this outside. You may want to have a lot of time, and for some, you might want to have medical personnel available.
To really do it as an active learning exercise, you need three student monitors, one for each loop, who will keep count and signal each iteration and the end.
First suppose that the <doSomething>
action is the same in all cases and is simple and fast, say clap hands. The three cases will have a different number of overall claps, of course, and the last will take a while.
Next, suppose that the <doSomething>
actions can be different for each occurrence (I'll still assume they don't depend on the current value of the iterator.) We might have something like the following:
Fully Un-nested
for (int i = 0; i < 10; i++) {
clapHandsOnce();
}
for (int j = 0; j < 10; j++) {
shout("hooray");
}
for (int k = 0; k < 10; k++) {
standUpSpinAroundSitDown();
}
Partially Nested
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
clapHandsOnce();
}
for (int k = 0; k < 10; k++) {
shout("hooray");
}
}
Fully Nested
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
for (int k = 0; k < 10; k++) {
clapHandsOnce();
}
}
}
Well, in the last case, hands are pretty sore by now, but the need for medical comes in if you try:
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
for (int k = 0; k < 10; k++) {
clapHandsOnce();
shout("hooray");
standUpSpinAroundSitDown();
}
}
}
Before you try it, I'd suggest you consider setting the upper limit of each loop a bit lower.
But still, the iteration values aren't used. So...
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
for (int k = 0; k < 10; k++) {
shout("" + i + j + k);
}
}
}
or
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
for (int k = 0; k < 10; k++) {
shout("" + 100*i + 10*j + k);
}
}
}
Night falls. Parents file lawsuits....
There is actually a version that might be doable, and more informative as well. Consider:
for (int i = 0; i < 10; i++) {
standUpSpinAroundSitDown();
for (int j = 0; j < 10; j++) {
shout("hooray");
for (int k = 0; k < 10; k++) {
clapHandsOnce();
}
}
}
Your monitors will have a bit more to do here, perhaps, choreographing their parts, but the interleaving is instructive as to what is going on.