Link to project:
How do I fix this?
Link to project:
This is the same issue you had here. At compile time, the name
encryptAgain does not exist as @toastedpitabread explained in the other topic. You declare it inside a
while loop. The compiler doesn’t evaluate conditionals, so it doesn’t know that
encryptAgain will be declared. You’ll need to declare it prior to the loop.
Anyway, I declared
encryptAgain in the nested while loop which is an even inner scope. I wanted to find a way to exit the nested loop and outer loop in the nested loop but I found out a way, using
But what if this happened:
You were making a game(video game; thi is actually realistic because I’m learning C# to make video games) and you have mini games(a nested loop, level 2) and inside the mini game(nested nested loop, level 3) you are asking the player something until they get a valid choice. But in the inner inner loop when the computer checks the variable(the variable is the one the what the user typed when it asked the question in the inner inner loop), it has to exit to the outer loop(2 levels out) but if the program exits the level 3 loop(inner inner loop) they will go to the level 2 loop which doesn’t have the answer that was entered by the question asked in the level 3 loop, the level 2 loop can’t decide whether to exit that loop because the exiting relies on a condition which needs the level 3 question’s answer. So I mean that level 2 doesn’t have access to level three to break out of the 2 loops. I need a way to declare the question’s answer so that all of the loops(all 3 loops) can acess it so that the program can break out of it. Maybe I should just only declare but not set a value to the level 3 answer like this:
it’s so that the variable can be accessed in any loop which has is needed since I think there is no way to break out of the 2 inner loops to the outer one in the level 3 loop since I can’t do this:
// level 3(asking the player if they want to play the mini game again until they answer a valid answer) // if ans is yes(player said they want to no play again) break (2); // used to break out 2 levels of the 3 level loop. (go to the main game and play more games if they say so) // else break; // it stops asking
Yeah, I mean that kind of structure? Is it possible to break out of a 3 level loop and break out of 2 levels but not use
I know that was long but I couldn’t really explain it that good.
I have fixed the Caesar Cipher game:
Look, here’s the code: