Using the Break statement does not necessarily make the logic of your codes inconsistent, and breaks are often useful for improving the readability of your code. But in response to your question, this can be achieved through the use of while loops and logical logical operators. A modified version of your code is given below, I tried to change it as little as possible so that you can see the code in this example. There are several logical errors in your code that I left in the example below, which you might want to examine. In particular, the line below will print “odd,” when in fact the number will be even. If you want to check whether the number arrays[0][first] odd, then instead of if (arrays[0][first] % 2 == 0) need the following if if (arrays[0][first] % 2 != 0) .
Logical error
if (arrays[0][first] % 2 == 0) { cout << arrays[0][first] << " is odd " << endl;
This is non-break code.
bool swapped = true; if (arrays[0][first] % 2 == 0) { cout << arrays[0][first] << " is odd " << endl; int i = 1; while ( (i < arraycount) && swapped) { int j = 1; bool if_odd = true; while ((j < arrays[i][0] + 1) && if_odd) { if (arrays[i][j] % 2 != 0) { int temp = arrays[i][j]; cout << "Array #" << 1 << " value " << arrays[0][first] << " swapped with " << "Array #" << i << " value " << temp; arrays[i][j] = arrays[0][first]; arrays[0][first] = temp; swapped = false; if_odd = false; } j++; } i++; } }
source share