Πέμπτη 29 Νοεμβρίου 2018

Revision 16 Version 9.5

For these changes I have to change Version. So I think in one or two revisions I have to move to 9.6.

1) Overflow in operators *= += /= -= (for decimals)
check the program with upper limit above 27 . Older revision show wrong results for factorial() (first function)

Function factorial (a) {
      def decimal f=1
      Flush
      {
            Loop
            read ? a as decimal
            if a=0 then exit
            f*=a : Push a-1
      }
      =f
}

Function factorial2 (a as decimal) {
  f(1, a)
  sub f(b as decimal , a as decimal)
        if a=0 then =b : exit
        f(a*b, a-1)
  end sub
}

For i=1 to 27
? factorial(i), i
? factorial2(i)
next i


2) New IF Then Else in one linew
Previous versions we have to do this (using a block of code between then and Else
If False then { Print "true"} Else Print "false"

We can use If  true Then  If True Then If  True .... which work for one line.
2.1

The same for Else.If so from this revision we can do the old  and the new
this is the old with blocks (we have to use them if we have multiple lines, or nested if)
if false then {
      print "ok" : print 12,67, 32 : goto 1000
} else.if false then {
             Print "Hello There"
             PRINT "OK1"
}  else.if false then {
      print "not ok2" : ? 12+12
} else 1000 ' a goto 1000
print "done"
1000 print "1000"


Now for on line we can use it without blocks  Do not use nested if without real blocks like the above.

if true then
      print "ok" : print 12,67, 32 : goto 1000
else.if false then
             Print "Hello There" : PRINT "OK1"
else.if false then
      print "not ok2" : ? 12+12
else  1000 ' a goto 1000
print "done"
1000 print "1000"



2.2
using colon to separate statements. We can use goto inside. This is one line (wrapped)
if true then print "ok" : print 12,67, 32 : goto 1000 else.if false then ? "HELLO THERE": PRINT "OK1" else.if false then print "not ok2" : ? 12+12 else ? "not found"
print "done"
1000 print "1000"


2.3
try these
if  false else if false then ? "ok1" else.if false then print "ok2" else if false then ? "done" else ? "ok3"
if  false else if false then ? "ok1" else.if false then print "ok2" else if true then ? "done" else ? "ok3"
if  false else if false then ? "ok1" else.if true then print "ok2" else if true then ? "done" else ? "ok3"
if  false else if true then ? "ok1" else.if true then print "ok2" else if true then ? "done" else ? "ok3"
if  true else if true then ? "ok1" else.if true then print "ok2" else if true then ? "done" else ? "ok3"

if  true then if false then ? "ok1" else.if false then print "ok2" else if false then ? "done" else ? "ok3"
if  true then if false then ? "ok1" else.if false then print "ok2" else if true then ? "done" else ? "ok3"
if  true then if false then ? "ok1" else.if true then print "ok2" else if true then ? "done" else ? "ok3"
if  true then if true then ? "ok1" else.if true then print "ok2" else if true then ? "done" else ? "ok3"
if  true then if true then ? "ok1" else.if true then print "ok2" else if true then ? "done" else ? "ok3"

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου

You can feel free to write any suggestion, or idea on the subject.