jump statement

how to jump to another statement in c++ using other than goto statement?
please help me!!!!
That's precisely what the goto statement is for.

Other ways to transfer control to another place in your program without using goto:
- loops (for, while, do/while)
- break
- continue
- return
- switch

http://www.cplusplus.com/doc/tutorial/control/
How about using functions?
I am doing my assignment but my lecturer forbid me from using function and goto,so right now I trying to find another solution
closed account (48T7M4Gy)
One simple way to solve this is just to have repetitive code in main. Obviously if the repetition is beyond about twice a function is better, but maybe that's what your lecturer is trying to demonstrate.

eg instead of adding up number pairs.

my lecturer forbid me from using function and goto


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main()
{
 int  a = 0 //etc as needed;
 cin >> a;
 cin >> b;
 cout << a+b;

 //then

  cin >> c;
  cin >> d;
  cout << c+d;

 // a function becomes a worthwhile consideration if there is no restriction?
 // if's etc for branching (with difficulty?)
}



Topic archived. No new replies allowed.