I am making a text adventure game, that uses a lot of classes, and definitely if statements. So mu question is this: Is there a way to 'break' out of an if statement, like the continue keyword for loops? I want this so I can go up the evaluation order for like a player going up to another room.
I mean. If you need to break out of an if statement, then you're design is probably poor and you should rethink it. I found some info on some "hacks" that you can use, see if you find something useful - https://goo.gl/ObdomP
Edit:
I'd perhaps do it this way if I absolutely had to -
1 2 3 4 5 6 7 8 9 10
for (int i = 0; i < 1; i++) // Put them in a for-loop that runs once, so you are allowed to use the keyword break
{
if (x == 5)
{
cout << "X is equal to: ";
break;
cout << x;
}
// Not that it breaks out of the entire for-loop aswell.
}
It's for a text adventure, exactly what I'm trying to do is this.
There is an integer name count.
Depending on count's value, you go into the specific if statement which gives a situation and then changes count.
Now I want to reevaluate count after each if statement.
Are you suggesting having a loop that checks the value of my variable count each iteration, and then evaluates each iteration? Then, yes, that's what I want.
I'm probably going to use that.
PS: This isn't really a programming question, because I am asking for debugging or anything, just my curiosity. It was my mistake to include parts about my adventure game though.
PS: This isn't really a programming question, because I am asking for debugging or anything, just my curiosity. It was my mistake to include parts about my adventure game though.
The motivation for your question doesn't have anything to do with its subject matter.
1. check variable count for value
2. Based on value of count, do corresponding if statement.
3. In that same if statement, change the value of count, such as incrementing or decrementing it.
4. Go to step 1.
I want to achieve this, but my initial question, NOW SOLVED, had me stuck at the start of step 4.