Post Reply 
Requesting ELSEIF
03-25-2017, 11:43 AM
Post: #9
RE: Requesting ELSEIF
(03-24-2017 05:38 PM)Han Wrote:  CASE blocks have similar logic to nested ELSE-IF blocks (exiting the block once a condition is met and relevant actions are executed). It doesn't make your code any shorter but can provide improved legibility.

Just to show you, here's the actual ANSI/ISO BASIC statement statement I'm converting:

PHP Code:
IF (1) OR (2) OR (3THEN
circleellipse, or hyperbola
   LET Xo 
= -Dr/(2*Ar)
   
LET Yo = -Er/(2*Cr)
   PRINT 
"translation = {"USING$("-%.####",Xo); ", "USING$("-%.####",Yo); "}"
   
LET r(1) = Ar/(Ar*Xo*Xo Cr*Yo*Yo Fr)
   
LET r(3) = Cr/(Ar*Xo*Xo Cr*Yo*Yo Fr)
   
LET r(6) = -1.0
   
IF ABS(r(1)) < ABS(r(3)) THEN    foci on x-axis
      LET a2 
ABS(r(1))
      
LET b2 ABS(r(3))
      IF 
2 THEN                 ellipse
         LET c1 
SQRa2 b2 )
         PRINT 
"foci = {±"USING$("-%.####",c1); ", 0.0000}"
         
PRINT "eccentricity ="USING$("-%.#####",c1 SQR(a2))
      ELSEIF 
3 THEN            hyperbola
         LET c1 
SQRa2 b2 )
         PRINT 
"foci = {±"USING$("-%.####",c1); ", 0.0000}"
         
PRINT "eccentricity ="USING$("-%.#####",c1 SQR(a2))
      
END IF
   ELSE                             ! 
foci on y-axis
      LET a2 
ABS(r(3))
      
LET b2 ABS(r(1))
      IF 
2 THEN                 ellipse
         LET c1 
SQRa2 b2 )
         PRINT 
"foci = {0.0000, ±"USING$("-%.####",c1); "}"
         
PRINT "eccentricity ="USING$("-%.#####",c1 SQR(a2))
      ELSEIF 
3 THEN            hyperbola
         LET c1 
SQRa2 b2 )
         PRINT 
"foci = {0.0000, ±"USING$("-%.####",c1); "}"
         
PRINT "eccentricity ="USING$("-%.#####",c1 SQR(a2))
      
END IF
   
END IF
ELSEIF 
4 THEN                   parabola
   
IF ABS(Ar) > ABS(CrTHEN        formx² 4·p·y 0
      LET Xo 
Dr/(2*Ar)
      
LET Yo = (Fr Dr*Dr/(4*Ar))/Er
      
PRINT "translation = {"USING$("-%.####",Xo); ", "USING$("-%.####",Yo); "}"
      
LET r(1) = 1
      LET r
(5) = Er Ar
      LET p 
= -r(5)/4
      
PRINT "focus = {0, "USING$("-%.####",p); "}"
   
ELSE                            ! formy² 4·p·x 0
      LET Xo 
= (Fr Er*Er/(4*Cr))/Dr
      LET Yo 
Er/(2*Cr)
      PRINT 
"translation = {"USING$("-%.####",Xo); ", "USING$("-%.####",Yo); "}"
      
LET r(3) = 1
      LET r
(4) = Dr Cr
      LET p 
= -r(4)/4
      
PRINT "focus = {"USING$("-%.####",p); ", 0}"
   
END IF
END IF 

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Requesting ELSEIF - toml_12953 - 03-24-2017, 05:30 PM
RE: Requesting ELSEIF - Han - 03-24-2017, 05:38 PM
RE: Requesting ELSEIF - toml_12953 - 03-25-2017 11:43 AM
RE: Requesting ELSEIF - compsystems - 03-24-2017, 06:21 PM
RE: Requesting ELSEIF - toml_12953 - 03-24-2017, 06:52 PM
RE: Requesting ELSEIF - Carlos295pz - 03-24-2017, 07:45 PM
RE: Requesting ELSEIF - compsystems - 03-24-2017, 08:16 PM
RE: Requesting ELSEIF - compsystems - 03-24-2017, 07:16 PM
RE: Requesting ELSEIF - toml_12953 - 03-24-2017, 07:33 PM



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