Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
3.00/5 (4 votes)
See more:
I have a large program which is encompassed by a do... while loop. It is dependent on a variable going under a certain number.

Here's the catch: The variable is found inside a for loop inside a for loop inside the do...while loop.

yeah, maybe I should change my layout (not entirely sure how).

To save me, does anybody know of a way I could access this variable or somehow escape the entire sequence? eventually this program will be just the start of another... so I can't say "stop everything".

Many thanks if there is a way, else sorry for the hastle! Have a nice day :-)
Posted
Comments
Akinmade Bond 3-Nov-12 13:18pm    
Could you share some of the code, we can't see your screen. :) And have you thought of 'break;'?
CPallini 3-Nov-12 17:26pm    
Cannot you just set the variable value inside another thread?

easy, use another variable which can store the value of your desired variable.
use label on your specific point and use goto statemnt to get there

C++
int x;
for (;;)
for(;;)
for(;;)
{
 int y=123;
 if(y==123){ x=y; goto mylabel;}
}

mylabel:
cout << x;


goto is not a good approach but has its advantages, when you dont want to use return statement and do want make a jump, just that goto can jump anywhere in a function which makes it dangerous....

ps: if you dont want to leave your sequence but just want to see your variable than remove goto statement from if clause. if it is not just a value you want, you can also use a pointer type to access your variable.
 
Share this answer
 
v2
Your programming style is wrong. Study best programming practices. You need to adopt a good programming style. If your program is hard to maintain as it becomes overgrown, this means your program is not scallable. Need to refactor. You have to move some piece of code in separate functions, and you instantly will escape many of your problems. Use debugger to see what your program is doing, and what your variables are. Even moving and separating functionalties is not enough. You will need OOP in this case.
 
Share this answer
 
If you can control your heap allocations - inside the large function - by the smart pointers
then you could try the "Exception-Trick"[^] as well :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900