HP Forums
ELSE IF END --> ELIF? - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: ELSE IF END --> ELIF? (/thread-1860.html)



ELSE IF END --> ELIF? - Joe Horn - 07-21-2014 12:08 PM

If you type the following code into a CAS program...

Code:
(x)->BEGIN
  IF 1==2 THEN x:=3;
  ELSE IF 4==4 THEN x:=5; END; END;
  RETURN(x);
END;

... then exit the program editor, then edit the program again, you'll see that it has turned into this:

Code:
(x)->BEGIN  
  IF 1 = 2 THEN x:=3; 
  ELIF (4==4) THEN x:=5;  END ;  
  RETURN(x);  
END;

The ELSE IF turned into ELIF, and one of the ENDs is gone. I don't see ELIF mentioned in any of the docs. Is this new in rev 6030? Borrowed syntax from C or C++ perhaps?


RE: ELSE IF END --> ELIF? - Helge Gabert - 07-21-2014 07:42 PM

I've seen that also since rev 6030. It is weird, but seems to run fine.


RE: ELSE IF END --> ELIF? - htom trites - 07-23-2014 03:40 AM

Logically they're the same, but if you go back to edit you may get confused, because you have to change the ELIF into an ELSE IF ... and then insert an END in the correct place.
Code:

if condition
  then statement
  else if condition
           then statement
           {else statement}
        endif
endif

It's a construct that seems to creeping in, and I see no good reason for it. In this case, it's easy to see, but if there's over a page or two of nested code, it seems designed to invoke the propagating error corrections gods.

(One of the reason I like labeled things and matching labels for their ends.
Code:

sue:begin
      jerry:if condition
                then statement
                else sam:if condition
                        then statement
                       {else statement}
                     endif(sam)
              endif(jerry)
end(sue)
I rarely get them, though. For a while I used a happy pretty-printer that used a long list of names, prepending and appending them as comments.)
)