Qbasicnews.com

Full Version: Absolute need of goto 4 correct functioning of loop routine.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Quote:Oh pulease people...sheesh why didn't I see this post earlier...stop arguing over GOTO already. It's like arguing over religion. :roll:

Yes, my evil master :evil:

Please do not punish us Cry

Nemesis
I thought that Na_th_an and I were doing pretty good at not arguing, honestly. We were discussing, and considering each others' points--which is a lot more than I can say for most "conversations" I've had about religion. :barf:

Kudos (M&M ones, in this case) for Na_th_an for approaching this topic with a point of view that is both rational and considerate. Very mature.

Bah humbug to those that discount the discussion simply because it's on a topic that's been beaten do death by a dead horse with a stick. Or whatever.

I'm not a big fan of "agreeing to disagree." I like discussing things that make people reevaluate their stances and opinions; sometimes, it results in advancement. Sometimes it's the other person's. Sometimes it's mine. Often it's both.

In this instance, Na_th_an gets to consider the use of stacking NEXT statements and refactoring code blocks. I get to consider using GOTO (which I never would have done before) to optimize complex, command-heavy programs for speed.

So, yes, the topic's been covered. But please don't blow it off unless you see people blindly shouting opinions at each other as facts. It doesn't advance us. Big Grin

*peace*

Meg.

edit: damn, I'm kind of bitchy today. :o I gotta stop posting. I don't usually..like..make an issue out of stuff.
Meg, just so you know, I'm gonna quote you forever with:
"been beaten do death by a dead horse with a stick. Or whatever."
:lol:
Hi, Meg,

Although I avoid GOTO like the plague, I sometimes find them useful and am not afraid to use them.

Below is a more fair presentation of your code that appears to argue that a single EXIT FOR is the same as a GOTO. Note that it produces
1234444434443434342343434343423...(blah-blah many)...3434

Now substitute GOTO for EXIT FOR and get only 123444443444.

A big difference. So to really exit, you would need three more EXIT FOR statements. Right?

Mac

Code:
PRINT : PRINT
FOR x1% = 1 TO 5
  PRINT "1";
  FOR x2% = 1 TO 5
    PRINT "2";
    FOR x3% = 1 TO 5
      PRINT "3";
      FOR x4% = 1 TO 5
        PRINT "4";
        q = q + 1
        IF q > 7 THEN EXIT FOR
NEXT x4%, x3%, x2%, x1%
Adios:
Wow. You are so right. I hate to admit it, but I must have made a very bad logical error while testing my stacked NEXT sample. I've gone back and attempted to duplicate my previous findings, and can not do so. I'm not sure what was different about my original code. :oops:

I will add this to my reasons for not wanting to exit prematurely out of FOR / NEXT loops. I typically don't use EXIT within nested loops (I use EXIT almost exclusively for functions, and within loops, I will alter the conditional variable to set the exitcondition to true).

That being said, if EXIT cannot kick out of nested loops, that does leave GOTO as the only command I can think of that can forward-jump out of nested loops without checking for an exitcondition once per nested loop. Why you'd want to do this (other than Na_th_an's use for optimizing a program for speed once you've already got it logically coded and working properly), I'm not sure. After all, you can always set the exitconditions true to exit loops.

It is something to consider though, and I thank you for pointing out my error. This enlightenment makes my thoughts a lot more similar to Na_th_an's.

*peace*

Meg.
Hi, Meg.

My turn. I pointed out that JohnK had a bug in his bowling program. It gives 30 points on a strike, when it should be 10 + next two balls.

You noted that I should check the instructions.

Ouch! True. He clearly states that a strike gets 30.

My definition of a bug has always been "deviation from written specifications", not "user does not like how the program runs".

In this case, the written specifications clearly state that if you get a strike, you get 30 points. I might not like how the program runs, but have to admit that it has no bug in that regard.

Thanks for pointing that out.

I will probably get a similar note from John. (*gulp*)

Mac
Your Exit sub/funk/for/do/etc would be translatet to a JMP in ASM and JMP is GOTO.
;*)
well in ASM is not JMP importatn?
Quote:well in ASM is not JMP importatn?

Very important.
Hi meg.

I am *not* a goto proponant. However, I've found it useful in this program, which I think is a reasonable way to program a small prime number calculator.



Code:
defint a-z
DIM SmallPrimes(1 to 3500) AS INTEGER

CLS
PRINT "This program sticks primes in an array then prints 'em"

'set initial values
a = 0
max = 3
smallprimes(1) = 3
next1 = 5
count = 1

'find first 3500 primes and put them in array, smallprimes()
'use 2-byte integer for small primes
DO WHILE count < 3500
  sqroot = SQR(next1)

  DO
      a = a + 1
      IF next1 MOD smallprimes(a) = 0 THEN GOTO notprime
  LOOP WHILE sqroot > smallprimes(a)

  count = count + 1
  smallprimes(count) = next1

notprime:

  next1 = next1 + 2
  a = 0
LOOP


FOR z = 1 TO 3500
   PRINT smallprimes(z);
NEXT z
Pages: 1 2 3