I am using C++11 std::list and list iterators. I use nested loops and test a condition and if it succeeds, I use goto statement to get out. A pseudo code is shown below:
std::list<myclass>::iterator tmpItr;
std::list<myclass>::iterator tmpItr2;
std::list<std::list<myclass>::iterator>::iterator radItr;
double cutoffVal = someVal;
double currVal = 0.0;
for (radItr=radList.begin();radItr!=radList.end();radItr++) {
tmpItr2 = *radItr;
for (tmpItr=pList.begin();tmpItr!=pList.end();tmpItr++) {
if (tmpItr == tmpItr2)
continue;
/* Some Operation Here */
currVal += NewVal;
if (currVal >= cutoffVal)
goto BREAKLOOP;
}
}
BREAKLOOP:
// Use tmpItr and tmpItr2
My problem is that sometime the value of tmpItr goes to list.end() and I get a segmentation fault. Does the goto statement somehow does post increment as well here?
goto, and it shouldn’t generally be a problem if/when your iterator equalslist.end().