how do you get the program to go back to a certain part in the program
how do you get the program to go back to a certain part in the program
// certain part of the program
certain_part:
// some code
// another part of the program
goto certain_part;
Be careful on how you use the goto statement. Use it ONLY if you really need it, but it would be much safer to break your code into small functions to enable to call a function instead of using a goto. Goto's can cause unwanted recursion and, like someone on this board once said "goto's can make your code look like a spaghetti".
Cheers.
1 rule of the Samurai Code: if you have nothing to say, don't say anything at all!
GOTO can b useful sometimes, although it is not good programming practice 2 use goto...
Dr. AL-Stevens - "Al-Stevens Teaches C" - BPB Publications
pg. 91
You can use more loops, alongwith the break and continue statements to do what you need. But, my suggestion is DO NOT USE gotoEveryone who writes about programming deprecates the goto statement and cautions you not to use it. I've written and published lots of C and C++ code without using goto. It has been conclusively proven that any algorithm can be designed with the three control structures of structures programming and without the goto statement.
I agree. You really should stay away from goto as much as possible.
However, used correctly and wisely goto is a very useful peice of the language...
Use functions.
void funct1(void);
void funct2(void);
int main()
{
int choice;
cout << "enter your option: 1) blah 2) blah";
cin >> choice;
switch(choice)
{
case 1: funct1();
break;
case 2: funct2();
break;
default: break;
}
return 0;
}
void funct1(void)
{
whatever here
}
void funct2(void)
{
whatever here as well
}
I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P
Oops... put the entire thing in a do-while loop, a while loop, or a forever loop using a break statment to go back to the portion of the program that you want to go back to. The type of loop depends on what condition you are testing for.
I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P