Hmm...not the worst use of a goto, but probably not the best either. There have been times that I really wish C supported labeled break/continue statements, but that's becoming rare. I am more than happy to simply move stuff into helper functions:
Code:
for (auto it = vec.begin(); it < vec.end(); ) {
process_vector_elements()
}
...
void process_vector_elements()
{
for (int i = 0; i < 4; ++i) { // use pre-increment in C++
if (t[i]) {
switch (x) {
case 23:
return;
When it hits that return, and process_vector_elements is done, the vector loop will proceed to the next element.
As for the pre-increment, it avoids having to call a copy constructor (since it doesn't have to save the old value of i).
The other nice thing about splitting up your function like this is you've separated the processing of a vector of objects, from the processing of a single object. That keeps your code loosely coupled and makes it easier to do things like unit test your code, since you have isolated the processing of a single foo object. And it will keep your code (or at least this part of it) goto-free.
Also, I hope you're not using magic numbers (4 and 23) in the real code. Some #defines and enums would do nicely here.
Last note:
This definitely seems to be C++. I'm not much of a C++ expert, but I can't recall ever seeing a good use of goto in C++. In C, however, the most common use that I've seen (and personally the only one I generally think is a good use of goto) is for error handling, so you can avoid deeply-nested if statements or repeating tedious cleanup code.