On Mon, Feb 19, 2001 at 05:57:31PM +1100, Bill Bennett uttered:
> I'm teaching myself QBasic from Schneider's book QBasic with an
> Introduction to VisualBasic. Please, forget the sarcasm: I'm
> a new convert to Linux and am looking for a QBasic equivalent
> even as we speak.
>
What sarcasm? *evil grin*
> Schneider is rather emphatic on structuring. He says:---
>
That putting it rather mildly.
> "There are four primary logical programming constructs: sequence,
> decision, loop and unconditional branch. Unconditional branch,
> which appears in some languages as GOTO statements, involves
> jumping from one place in a program to another. Structured
> programming uses the first three constructs, but forbids the
> fourth. One advantage of pseudocode over flowcharts is that
> pseudocode has no provision for unconditional branching and thus
> forces the programmer to write structured programs."
>
> and later:---
>
> "One major shortcoming of the earliest programming languages was
> their reliance on the GOTO statement. This statement was used to
> branch (that is, jump) from one line of a program to another. It
> was common for a program to be composed of a convoluted tangle of
> branchings that produced confused code referred to as spaghetti
> code. At the heart of structured programming is the assertion of
> E.W.Dijkstra that GOTO statements should be eliminated entirely
> since they lead to complex and confusing programs. Two Italians,
> C.Bohm and G.Jacopini, were able to prove that GOTO statements
> are not needed and that any program can be written using only the
> three types of logic structures discussed above.
>
MUAHAHAHAHAHAHHAHAHA.
Read all, or most of them before.
To use goto, or not to use goto.
I'm firmly in the latter camp, _except_ for one condition (and in Qbasic only):
ON ERROR GOTO
So, using that, you could call me a structured programmer, but then again, you haven't
seen my Perl code.
> Structured programming requires that all programs be written
> using sequences, decisions, and loops. Nesting of such statements
> is allowed."
>
> Well, I can see his point. I read (this interest group, I think)
> that if you can't come back to a program after three weeks and
> understand it, something's radically wrong. Spaghettification
> wouldn't help.
>
Agreed.
> On the other hand, I think I have encountered one of Schneider's rare
> instances where you *have* to use a GOTO; if I'm right then it's
> not all *that* rare.
>
> And the next time I'm in Sydney, if there's a Slug gathering,
> I'd be happy to buy drinks for those who helped...
>
Woooo! :-)
> Regards,
>
> Bill Bennett.
>
> ------------------------------------------------------
>
> A Game of Noughts and Crosses (aka Tic-Tac-Toe)
>
> I've divided the problem into tasks and the tasks have become
> subprograms. Their names are (or should be) self-explanatory.
>
> CLS
> DIM TheBoard$(1 TO 3, 1 TO 3)
> CALL SetTheBoard(TheBoard$())
> CALL DisplayTheBoard(TheBoard$())
> CALL TheFirstEntries(FirstPlayer, SecondPlayer, TheBoard$())
> CALL Continuing(FirstPlayer, SecondPlayer, TheBoard$())
> CALl TestRowsColumnsDiagonals(TheBoard$(), flagStatus, cellEntry$)
> CALL ReportStatus(flagStatus, cellEntry$)
> END
>
Ewwww.
It's _just_ a game of TicTacToe. Did he have to sub the living hell out of it?
> Consider the subprogram TheFirstEntries. This sorted out
> the first X and the first 0; this was to give me some idea
> of counters and procedures. I wanted to put in a contigency
> trap: someone who consistently didn't choose an X or a 0. 3
> incorrect responses and the program quits.
>
> Well, the generic loop for this is:---
>
> Select a response, if it's wrong(1)/wrong(2)/wrong(3), a flag=1
> and the far end of the loop is LOOP UNTIL FLAG=1
>
> All very well, except that this is a contingency occurring early
> in the process. Even if the flag =1, the process will still
> continue down the loop. I'd like to find a way (other than using
> GOTO) simply to jump out of the loop, jump over the intervening
> subprograms (which are all concerned with continuing after a
> correct response has been received) and simply quitting.
>
C, Perl, a few others (not sure about Basic - I __think__ it does) have:
break();
Shown in a C stylee for simpilicties sake. Now, C/Perl/Python (?) treat this is the
Right Way and dump themselves out of the loop. I also remember that Basic uses break
to set a breakpoint, or something. Ah, well.
> According to Schneider, it should be possible using only
> sequence, decision and loop. Perhaps even a loop is unnenessary.
>
> I still can't see how.
>
A Pre-test loop would be best:
WHILE (not won) {
<other instructions>
if (moves > 3) {
won = 1;
}
}
There's my stab at it. I'll look at it when i'm bored at work, and am more awake. :-)
> ----------------------------------------------------------
>
> --
> SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
> More Info: http://slug.org.au/lists/listinfo/slug
>
--
Steve
"I'm a sysadmin because I couldn't beat a blind monkey in a coding contest."
--Me
--
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug