changing an if statement to a while loop

I have some code where I've created a maze, and there is an if statement followed by a goto to get back to the level menu after finishing a level. However, I would rather have it as a while loop, would anyone be able to tell me how to do so?

The code I want to change is as follows:

case 'd':
x = getPos(lvl, y);
if (!isWall(x + 1, y, lvl)) {
if (isExit(x + 1, y, lvl)) {
system("CLS");
cout << "You Win!" << endl;
Sleep(2000);
goto begin;;
}
system("CLS");
makeSpace(lvl, x, y);
update(lvl, x + 1, y);
}
break;

for example.

You would have to surround all of the code that includes the switch statement and all logic between the begin label and the goto statement inside of the while loop.

It might take some refactoring to make a change like that based on what you've shown, but you haven't shown the part that contains the begin label or anything...
Topic archived. No new replies allowed.