Author Topic: Enhanced Features For QB64  (Read 6052 times)

0 Members and 1 Guest are viewing this topic.

Offline eoredson

  • Newbie
  • Posts: 55
  • Let the Farce be with you!
    • View Profile
    • Oredson QB45 Files At Filegate
Enhanced Features For QB64
« on: July 21, 2017, 10:37:58 pm »
   Combined Selection/Iteration statements:

      Proposed to QB64 is the fourth programming structure, the combined
      Selecta-iterative structure.

      FORIF <cond>, <var>=<exp1> [TO <exp2>] [STEP <exp3>] [EXCEPT <exp4>]
         EXIT FORIF [<n1>]
      NEXTIF

         Where <cond> is the initial start condition, <exp1> is for starting
         loop value, <exp2> is the ending loop value, <exp3> is the step
         variable, and <exp4> is the except variable.

         Defines the start of a forif/nextif loop structure where <cond> is
         the condition which determines the continuation of the forif loop,
         <var> is any variable form A to Z, and <exp> is any expression. If
         the step variable is omitted then it defaults to one. If the except
         variable is omitted it defaults to none. There is space for 26
         nested loops.

         The forif loop repeats for the positive increment of one from the
         first expression to the second and when the counting of the loop
         exceeds the second expression, the loop jumps to the statement
         following the matching next statement, dependent on the start
         condition <cond> which determines if the loop starts. For example:

            FORIF M=-1,L=1 TO 10

         starts the loop if M is -1, then increments L from 1 to 10,
         executing all statements between the for and the matching nextif.

    The step variable increments the variable loop by a different
    specified value other than the default of one, for example:

            FORIF M=-1,L=1 TO 10 STEP 2

         increments L from 1 to 10 by steps of 2, if M is -1, executing all
         statements between the for and the matching nextif. If the start
         expression is greater than the second expression, the step should
         be a negative value, for example:

            FORIF M=-1,L=10 TO 1 STEP -1

         decrements L from 10 to 1, if M is -1, executing all statements
         between the for and the matching next.

         The except variable skips values in the loop of a specific
         expression, for example:

            FORIF M=-1,L=1 TO 10 STEP 2 EXCEPT 5

         increments L from 1 to 10, if M is -1, by steps of 2, skipping 5,
         executing all statements between the for and the matching next.

      NEXTIF

         Concludes the definition of a forif/nextif loop structure. If the
         nextif cannot find the start forif, or if the forif cannot find the
         matching nextif, a 'Mismatched forif/nextif.' error is displayed
         and the program terminated. Note however that the value of the
         variable of the forif counter after the program continues with the
         statement following the nextif cannot be relied upon for a specific
         value.

      CONTINUE FORIF [<n1>]

         Jumps to the matching nextif from within a forif/nextif loop,
         ignoring the remaining statements in the loop.

         For example:

            10 INPUT M
            20 FORIF M=-1,L=1 TO 10 STEP 2
            30    IF L>8 THEN
            40       CONTINUE FORIF
            50    END IF
            60    PRINT "Loop counter at ";L
            70 NEXTIF

      EXIT FORIF [<n1>]

         Jumps to the statement following the matching nextif from within a
         forif/nextif loop, ignoring the remaining statements in the loop.

         An example of a complete forif/nextif loop could be:

            10 INPUT M
            20 FORIF M=-1,L=1 TO 10 STEP 2
            30    PRINT "Loop counter at ";L
            40    IF L=9 THEN
            50       EXIT FORIF
            60    END IF
            70 NEXTIF

         Additional loop notes:

         The continue and exit statements may also specify the number of
         nested loops to exit by adding the number to the statement.

         For example:

            10 INPUT M, P
            20 FORIF M=-1,L=1 TO 10 STEP 2
            30    PRINT "Counter 1";L
            40    FORIF M=-1,O=1 TO 10
            50       IF O=P THEN
            60          EXIT FORIF 2
            70       END IF
            80       PRINT "Counter 2";O
            90    NEXTIF
            100 NEXTIF

      LOOPIF <cond> [UNLESS <exp1>]
         EXIT LOOPIF [<n1>]
      END LOOPIF

         Defines the ending loop of the do/loop structure where the start
         of the loop is a loopif. If the condition in <cond> is true, then
         the loop starts. The exit loop can optionally exit <n1> number of
         loop ends. If the loopif/end loopif is not matched with a beginning
         loopif, a "Mismatched loopif/end loopif." error is displayed and
         the program ended. Example:

            10  INPUT X
            20  LOOPIF X/2=X\2
            30     FOR Y=1 TO 10
            40        IF Y>4 THEN
            50           EXIT LOOPIF
            60        END IF
            70        PRINT Y;
            80     NEXT
            90  END LOOPIF
            100 PRINT

      SELECTIF CASE <c1>,<v1>
      CASEIF <n1>,<n2>, ...
      CASEIF ELSE
      END SELECTIF

         Calculates the condition in <c1>, then calculates test-value
         and compares the value to the following expressions in the caseif
         statements, implementing the program statements after the first
         matching value, if the selectif condition is true. If none of the
         case expressions match the test-value then the caseif else structure
         is implemented. Multiple caseif expressions can be separated on one
         line with commas, then each expression is compared against the
         test-value, and the caseif statements implemented if any expression
         matchs the selectif case test-value. Select cases may be nested.
         Caseif else may be omitted.

         Expressions can also be an operation of two values starting with
         the IS or ISNT keyword, such as, IS>10, for example:

            10 SELECTIF CASE M=0,X
            20 CASEIF IS>10
            30    PRINT X
            40 END SELECTIF

         Only if M is equal to 0.

         Expressions with both IS and ISNT expressions result in a true
         condition when the first value matchs the test-value, for example:

            10 SELECTIF CASE M=0,X
            20 CASEIF IS>10,ISNT>20
            30    PRINT X
            40 END SELECTIF

         results in printing x if x is greater than 10, and even if x is
         greater than 20 since the test-value matchs IS>10 first, only if
         the variable M is equalt to 0.

         Expressions can also be a range of values separated with == symbols,
         the range being inclusive, for example:

            10 SELECTIF CASE M=-1,X
            20 CASEIF 1==5
            30    PRINT "X is between 1 and 5."
            40 END SELECTIF

         And case expressions can be mixed, for example:

            10 SELECTIF CASE M=-1,X
            20 CASEIF 1,2,4==10,IS>15
            30    PRINT X
            40 END SELECTIF

         Case expressions may also be string, for example:

            10 SELECTIF CASE Y$="Y",X$
            20 CASEIF "A","B",IS>"w"
            30    PRINT X$
            40 END SELECTIF

      Combined Selection/Iteration statement examples:

         Display 1 to 10 if X is divisible by 2:

            10 INPUT X
            20 FORIF X/2=X\2,Z=1 TO 10
            30    PRINT Z;
            40 NEXTIF
            50 PRINT

         Display 1 to 10 if X is true, and Y between 1 to 2, or 4 to 5:

            10 INPUT X,Y
            20 SELECTIF CASE X=-1,Y
            30 CASEIF 1==2,4==5
            40    FOR Z=1 TO 10
            50       PRINT Z;
            60    NEXT
            70    PRINT
            80 END SELECTIF
« Last Edit: July 22, 2017, 12:26:00 am by eoredson »

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: Enhanced Features For QB64
« Reply #1 on: July 22, 2017, 12:04:10 am »
I see no reason to complicate things for the sake of a little syntactic sugar.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Enhanced Features For QB64
« Reply #2 on: July 22, 2017, 03:46:49 am »
Hi, On the above examples, everyone can write their own SUB with this name, it can be simply folded over to DO... WHILE... LOOP  followed by FOR ... TO ... NEXT ... STEP. In order to maintain the functionality FOR ... TO ... NEXT .... STEP, muss there be condition for STEP. For example FOR X  = 0 TO 10 STEP -1 is unsense, this muss be controled.