Doing this without goto

Everybody says that goto is notorious to being obsecure

So I want to clean my code from having this goto
so how do I do that ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

void function( MyClass * p, MyClass * q ){
	
	MyClass * ptr = p;
loop:
	// do many things with    *ptr, p and q
	
	if( ptr == p ) {
		ptr = q;
		goto loop;
	}


}

Last edited on
1
2
3
4
5
6
7
void function(MyClass *p, MyClass *q)
{
    for (MyClass *ptr = p; ptr == p; ptr = q)
    {
        // Do many things with *ptr, p, and q
    }
}
Everybody says that goto is notorious to being obsecure

Never heard anyone say that. Whatever that means.


1
2
3
4
5
6
7
8
9
10
11
12
13
void function( MyClass* p, MyClass* q ) {

    MyClass* ptr = p ;

    for ( ; ; )
    {
        // do many things with *ptr, p and q
        if ( ptr == p )
            ptr = q ;
        else
            break ;
    }
}
Last edited on
I mean that most of the time goto make simple things looks difficult

Anyway, Thanks for the reply..
Last edited on
Topic archived. No new replies allowed.