What is the difference between the following two constructs? I am getting a different output for each:
for (int counter = 0; (counter < numberOfFolds) && counter != currentFold; counter++)
{
if (instances[counter] < minimum)
{
return (currentFoldHasAtleastMinimum && true);
}
}
AND
for (int counter = 0; (counter < numberOfFolds); counter++)
{
if (counter != currentFold)
{
if (instances[counter] < minimum)
{
return (currentFoldHasAtleastMinimum && true);
}
}
}
Essentially, the second block of code, simply breaks the compound condition in the for loop and takes it inside using an additional if statement (I may be missing something very fundamental here, and it may be really stupid, but I thought they were the same).
Please help. It appears that they are in fact not the same, and I cannot figure out why.
In the first example, when
counteris equal tocurrentFoldthe loop terminates.In the second example, the loop will continue when that condition is met, and instead will only terminate when
counter < numberOfFoldsis false.