As a general form you can use something like
need_to_repeat_outer_loop = true;
while need_to_repeat_outer_loop
need_to_repeat_inner_loop = true;
while need_to_repeat_inner_loop
if some inner condition
need_to_repeat_inner_loop = false;
end
end
if some outer condition
need_to_repeat_outer_loop = false;
end
end
Hower, in practice most of the time you would instead write
while true
while true
if some inner condition
break;
end
end
if some outer condition
break;
end
end
Sometimes you are inside the inner loop and need to signal that the outer loop is to be stopped. For that you can use
while true
while true
stop_outer = false;
if some inner condition
stop_outer = true;
break;
end
end
if stop_outer;
break;
end
end
Best Answer