Requesting ELSEIF
03-25-2017, 11:43 AM
Post: #9
 toml_12953 Senior Member Posts: 2,104 Joined: Dec 2013
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 (t = 1) OR (t = 2) OR (t = 3) THEN! circle, ellipse, 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(1 / r(1))      LET b2 = ABS(1 / r(3))      IF t = 2 THEN                 ! ellipse         LET c1 = SQR( a2 - b2 )         PRINT "foci = {±"; USING$("-%.####",c1); ", 0.0000}" PRINT "eccentricity ="; USING$("-%.#####",c1 / SQR(a2))      ELSEIF t = 3 THEN            ! hyperbola         LET c1 = SQR( a2 + b2 )         PRINT "foci = {±"; USING$("-%.####",c1); ", 0.0000}" PRINT "eccentricity ="; USING$("-%.#####",c1 / SQR(a2))      END IF   ELSE                             ! foci on y-axis      LET a2 = ABS(1 / r(3))      LET b2 = ABS(1 / r(1))      IF t = 2 THEN                 ! ellipse         LET c1 = SQR( a2 - b2 )         PRINT "foci = {0.0000, ±"; USING$("-%.####",c1); "}" PRINT "eccentricity ="; USING$("-%.#####",c1 / SQR(a2))      ELSEIF t = 3 THEN            ! hyperbola         LET c1 = SQR( a2 + b2 )         PRINT "foci = {0.0000, ±"; USING$("-%.####",c1); "}" PRINT "eccentricity ="; USING$("-%.#####",c1 / SQR(a2))      END IF   END IFELSEIF t = 4 THEN                   ! parabola   IF ABS(Ar) > ABS(Cr) THEN        ! form: x² - 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 ! form: y² - 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 IFEND IF

Tom L
Cui bono?
 « Next Oldest | Next Newest »

 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)