Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
BOWLING for John
#41
Who really cares! I never even got what I asked for. All I want is a compiler that will change BOWLING from .bas to .exe, and accepts WIDTH. *Thanks anyway to Meg, Mac, and Z!re for the help.*

:wink: :rotfl: :bounce: :oops: :barf: :wink: :rotfl: :bounce: :oops: :barf:
Reply
#42
QB45 aka QBasic 4.5
QB71 aka QBasic 7.1 aka PDS 7.1


In both: Run->Make EXE File
Reply
#43
na_th_an:

EXIT FOR is used only to jump out of a FOR loop. That is its only use. Therefore, if you code your FOR loops well, EXIT FOR is very logical and easy-to-follow.

GOTO is used to jump to any pre-defined location within your code. You can use it to exit a FOR loop, but the EXIT FOR command already does that. Use of GOTO strays from <emphasis>MY OPINION</emphasis> of clean programming:

Linear execution with indented loops using subroutines and functions to block off logically independent sections of code.

I see GOTO as serving three purposes:

1. moving backwards to a previous point in a program (looping): in this case, a properly-planned DO/UNTIL, WHILE/WEND, or FOR/NEXT loop would make more sense.

2. skipping ahead, over lines of code: in this case, properly-planned IF/THEN statements and use of subroutines to block off logically related pieces of code makes more sense.

3. getting out of a loop when a condition is met: in this case, the EXIT (FOR/DO/WHILE) command serves the same purpose, as has already been covered.

j2krei08: Have you looked at the code I posted?

*peace*

Meg.
Reply
#44
Use whatever fits you more, my friend Smile. I do use EXIT FOR, I follow your logic, I just was making a point: it is the same, both things do the same, the code looks the same.

Also, just for the sake of it, try to translate this to EXIT FORs:

Code:
FOR i% = 1 TO 31
   FOR j% = 1 TO 31
      FOR k% = 1 TO 31
         IF (i% MOD 2) = 0 AND (j% MOD 3) = 0 AND (k% MOD 5) = 0 THEN GOTO outside
NEXT k%, j%, i%
outside:

I'll do it for you:

Code:
FOR i% = 1 TO 31
   FOR j% = 1 TO 31
      FOR k% = 1 TO 31
         IF (k% MOD 5) = 0 THEN EXIT FOR
      NEXT k%
      IF (k% MOD 5) = 0 AND (j% MOD 3) = 0 THEN EXIT FOR
   NEXT j%
   IF (k% MOD 5) = 0 AND (j% MOD 3) = 0 AND (i% MOD 2) = 0 THEN EXIT FOR
NEXT i%

Now tell me what's more easily understandable. You need twice as code.

As I say, we both agree that we should tell newbies not to use GOTO when they can use better structures, for example to jump back or forth in the code, but you have to agree with me that GOTO has its uses and that using it intelligently when you have to doesn't make you a bad coder, but just the contrary.

I am talking about game loops where every cycle you save is vital.

A different case is, for example, using GOSUB. It is just deprecated, the introduction of SUBs with QB 2.0 and FUNCTIONS with QB 4.0 have made it completely useless. It is uglier and hard to read, so it's better to avoid it. Using GOSUB is just like use LET to define variables or CALL to call subroutines, but even worse. GOTO is also ugly and hard to read, but as still has its uses, I will still use it. And I can guarantee you that when you read my code you'll understand it completely.

Also note that I am talking about optimizing. I often use structured techniques in my programs but when I go for cycle hunting I change some stuff to its ugly (but faster) equivalent. For example, when you code a scripting engine for a game that has to read through a script file really often. You can't waste even a single extra comparison.

Note that this is not an endless rant, nor I want to stay "victorious" or something (It may look that way). I was just defining my scenario. There are different ways of coding different sorts of things. When you are teaching how to code someone, you better go with recursive algos, for example. When you apply them, you better turn them to iterative. They look ugly and sometimes almost unreadable (everyone should understand the recursive quicksort, but understanding the iterative one at first sight may be hard). Note that I was not critizising the claim "don't use GOTO" made to the newcomer. I was critizising the use of the sentence as a global truth, written on stone in the top of Everest. I think you all did an excellent work pointing this guy to the proper way of doing things, I don't want even a single shadow of doubt over that aspect.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#45
Hi, Meg,

Hehe - We've thouroughly hijacked JohnK's request, so one more post:

http://www.network54.com/Forum/message?f...1106922252

That's your first improvement. Note I have added even more. LOL!

With enough changes, we can do to JohnK what I did to Gibberish's game:
http://www.network54.com/Forum/273951

Mac


Mac
Reply
#46
[syntax="QBASIC"]
FOR i% = 1 TO 31
FOR j% = 1 TO 31
FOR k% = 1 TO 31
IF (i% MOD 2) = 0 AND (j% MOD 3) = 0 AND (k% MOD 5) = 0 THEN EXIT FOR
NEXT k%, j%, i%
[/syntax]

This works fine. Although, as you stack more FOR loops inside each other, I'd rather see the inner ones be contained in subs, instead of one huge nested FOR x1 FOR x2 FOR x3 FOR x4 NEXT x4,x3,x2,x1 loop.
Reply
#47
That was just an example. And EXIT FOR just exits one for loop, not the three of them. At least upon QB help.

And making SUB to nest FORs is just slow and unneeded.

And I think you didn't read the rest of my post. I told more things. Got no reply. Cool Smile
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#48
To end all this goto madness, check out the challenges index.
I'm posting a absolutely needed goto statement challenge!
Anyways, I remeber using goto all the time when I was in grade school, I'd use goto to prematurely exit a gosub-routine alot of times... Then I'd just use my favorite command (at the time in apple-soft basic)... POP!!!
Everyone in class thought I was a real pro because I used POP,
nobody could understand this logic... not even the teacher :rotfl:

Cya in the GOTO challenge thread!

Nemesis
Reply
#49
The strength/speed had nothing to do with anything. It was just there for looks.

:wink: :rotfl: :bounce: :oops: :barf: :wink: :rotfl: :bounce: :oops: :barf:
Reply
#50
Well, that was a long enough wait. I put Bowling, with better graphics, on Pete's site. Download and rate it!

http://www.petesqbsite.com/downloads/bowling.zip
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)