Post Reply 
HP Prime speed vs TI-Nspire CX
11-09-2016, 08:44 AM
Post: #21
RE: HP Prime speed vs TI-Nspire CX
I use a construct like the following for most programs that do real work.

J=1
While (J Ne 0) DO
Case j=1 Then.... j = x End
j=2 Then.... j = y End
j=3 Then.... j=z End
End

Sort of a pseudo-hp50g code. It allows an arbitrary state machine to be written in Structured Programming. (I don't remember the Prime commands as I no longer use the Prime; trying to update it's memory fried a rather expensive desktop and the Prime was banished.)

Without GOTOs, error handling is hard. Most modern languages do have enough constructs to make GOTOs irrelevant. They are not needed for looping or branching. They are really only useful when one needs to jump across contexts without unwinding the whole context (mostly in error handling.)
Find all posts by this user
Quote this message in a reply
11-09-2016, 12:01 PM
Post: #22
RE: HP Prime speed vs TI-Nspire CX
(11-09-2016 06:48 AM)cyrille de brébisson Wrote:  Hello,


BUT, 90% of my goto use is to exit multiple loops at once, which you can not do in C (or other programming languages)... HOWEVER, you CAN do it in PPL using the BREAK(n) and CONTINUE(n) function!!!! As far as I know, PPL is the ONLY language that has such constructs!!!

Cyrille

Hello,
I have doubts if I understood correctly, but in Fortran 90 onwards one can do the following:

Code:
0| outa: DO
1|    inna: DO
2|      -----


5|      IF (cond1) EXIT outa ! jump line 9
6|      IF(cond2) CYCLE outa!jump line 0
7|     END DO inna
8| END DO outa
9|-----

Marcelo
Find all posts by this user
Quote this message in a reply
11-09-2016, 01:00 PM (This post was last modified: 11-09-2016 01:13 PM by toml_12953.)
Post: #23
RE: HP Prime speed vs TI-Nspire CX
(11-09-2016 08:44 AM)ttw Wrote:  Without GOTOs, error handling is hard.

In ANSI (ISO) BASIC, error handling is done this way:

WHEN EXCEPTION IN
<code block>
USE
<error handling code>
END WHEN

Contrived simple example: square root error

Code:
DO
   LET ERRFLAG = 0
   INPUT PROMPT "ENTER A NUMBER": N
   WHEN EXCEPTION IN
      LET X = SQR(N)
   USE
      PRINT "ERROR IN SQUARE ROOT"
      LET ERRFLAG = -1
   END WHEN
LOOP UNTIL ERRFLAG = 0
PRINT "THE SQUARE ROOT OF";N;";"IS";X
END

No need for GOTO even in error handling.

Tom L

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
11-09-2016, 01:35 PM (This post was last modified: 11-09-2016 01:36 PM by Adriweb.)
Post: #24
RE: HP Prime speed vs TI-Nspire CX
(11-09-2016 06:48 AM)cyrille de brébisson Wrote:  BUT, 90% of my goto use is to exit multiple loops at once, which you can not do in C (or other programming languages)... HOWEVER, you CAN do it in PPL using the BREAK(n) and CONTINUE(n) function!!!! As far as I know, PPL is the ONLY language that has such constructs!!!

PHP has this too, and I'm sure others I'm not so familiar with or don't know at all.

TI-Planet.org co-administrator
Find all posts by this user
Quote this message in a reply
11-09-2016, 08:00 PM
Post: #25
RE: HP Prime speed vs TI-Nspire CX
For resurrecting old BASIC listings (if only to see what they do before a rewrite) most labels could be restricted to the same procedure... Most old listings with lots of GOTO's made little use of procedures.

When I have used GOTO for error handling, I have never needed the context to be preserved:
If engine==off and restart()==off goto Failure;
...
Failure: Reboot();//or Halt();

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
11-10-2016, 07:05 PM
Post: #26
RE: HP Prime speed vs TI-Nspire CX
(11-09-2016 01:35 PM)Adriweb Wrote:  
(11-09-2016 06:48 AM)cyrille de brébisson Wrote:  HOWEVER, you CAN do it in PPL using the BREAK(n) and CONTINUE(n) function!!!! As far as I know, PPL is the ONLY language that has such constructs!!!

PHP has this too, and I'm sure others I'm not so familiar with or don't know at all.

As does bash.

Whenever I use goto to exit a heavily nested C loop, I always add a comment like // break(4)
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)