Posted: Mon May 15, 2006 2:40 pm
				
				still no good example of the valid use of a goto or gosub... makes me think... in fact, i'd even like to see a good example of a break statement... that shouldn't be so hard, should it?
			http://www.purebasic.com
https://www.purebasic.fr/english/
Gosub/Gotos are bad IMHO but Break can be used to optimise code a great deal! I mean why traverse hugh loops in their entirity looking for matching values when you can just leave the loop when you find what you are looking for. Break, can speed code up no end and it's a very easy command to use and understand in your code, unlike Gosub/Goto, which can lead you anywhere....blueznl wrote:still no good example of the valid use of a goto or gosub... makes me think... in fact, i'd even like to see a good example of a break statement... that shouldn't be so hard, should it?

 but if Break can be used to exit a loop (stopping when a certain condition occurs) and do something, whats the difference in using a GOTO or GOSUB to accomplish the same thing? Isn't GOTO, GOSUB, BREAK and CONTINUE just calling the same flow control method by different names? And, i'm confused as to why GOTO and GOSUB would lead you anywhere when you need to specifically give them a target to GOTO or GOSUB to, when BREAK or CONTINUE do the same thing just in a different place where you don't need to give them a specific target and they just do it because they happen to be the next command in line?
 but if Break can be used to exit a loop (stopping when a certain condition occurs) and do something, whats the difference in using a GOTO or GOSUB to accomplish the same thing? Isn't GOTO, GOSUB, BREAK and CONTINUE just calling the same flow control method by different names? And, i'm confused as to why GOTO and GOSUB would lead you anywhere when you need to specifically give them a target to GOTO or GOSUB to, when BREAK or CONTINUE do the same thing just in a different place where you don't need to give them a specific target and they just do it because they happen to be the next command in line?Kale wrote:Gosub/Gotos are bad IMHO but Break can be used to optimise code a great deal! I mean why traverse hugh loops in their entirity looking for matching values when you can just leave the loop when you find what you are looking for. Break, can speed code up no end and it's a very easy command to use and understand in your code, unlike Gosub/Goto, which can lead you anywhere....blueznl wrote:still no good example of the valid use of a goto or gosub... makes me think... in fact, i'd even like to see a good example of a break statement... that shouldn't be so hard, should it?

lol, let's just end this discussion rigth herethefool wrote:I can come with some good examples on where and how to use goto.

Code: Select all
function test(a)
for x = 1 to 1000
for y = 1 to 1000
for z = 1 to 1000
q=f(a,x,y,z)
if q>SomeImportantLimit then GOTO Failed
next
next
next
update something important with q
exit function
Failed:
HandleProblem
end functionCode: Select all
function check(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,state)
if f(all parameters) > limit then
	do one thing
else
	do other thing
endif
end function
..
a=1:b=2:c=3...z=26
state=check1
check(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,state)
state=check2
check(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,state)
state=check3
check(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,state)
state=check4
check(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,state)
state=check5
check(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,state)Code: Select all
check:
if f(all parameters) > limit then
	do one thing
else
	do other thing
endif
return
 
 
a=1:b=2:c=3...z=26
state=check1
gosub check
state=check2
gosub check
state=check3
gosub check
state=check4
gosub check
state=check5
gosub check
..seriously!Joakim Christiansen wrote:lol, let's just end this discussion rigth herethefool wrote:I can come with some good examples on where and how to use goto.

 
 heheHades wrote:@thefool

Sorry, forget it. It will work. It's just because it's so much against the way I'm thinking to just jump out of a loop, I thought it has to break something.

Lol! I would love for you to demonstrate that last point with a real world example. You are just plain crazy if you think that using goto's make code easier to follow.dioxin wrote:I say that GOTO and GOSUB have their legitimate place. They can be very useful and they aren't the evil codewreckers that some would have you believe...
...Trying at all costs to avoid them will often lead to less easy to follow code.