From Schaums C++ text
Removal of goto- says use a flag
code segment:
const int N2 = 5;
int i, j, k;
for (i = 0; i < N2; i++)
{ for (j = 0; j < N2; j++)
{ for (k = 0; k < N2; k++)
if (i + j + k > N2)
goto esc;
else
cout << i + j + k << " ";
cout << "* ";
}
esc: cout << "." << endl;
}
The solution:
const int 5;
int i, j, k;
bool done = false;
for (i = 0; i < N2; i++)
{ for (j = 0; j < N2 && !done; j++)
{ for (k = 0; k < N2 && !done; k++)
if (i + j + k > N2)
done true;
else
cout << i + j + k << " ";
cout << "* ";
}
cout << "." << endl;
done = false;
}
The output of the structured solution does not produce the same result...as the goto one... I can't see the problem
- Also, what would be another way to eliminate the goto?- Could I not use a flag and just compliment the condition.
Thanks ...