Aug.05.2017 -- CAlive to introduce breakN, and scope breaks

7 views
Skip to first unread message

Rick C. Hodgin

unread,
Aug 5, 2017, 1:06:30 PM8/5/17
to caliveprogra...@googlegroups.com
CAlive will introduce the breakN; command, to break out of multiple relative scopes.  In addition, the sbreak; and sbreakout; keywords, allowing a break out of either the immediate scope or to the next-outer scope depending on whether or not the immediate scope is an if {..} block, or all the way out to the function-level scope.  In addition, each scope can be named and the option sbreak name; can be used to exit out to that level of scope.

    function sample_breakN
    | params int tnA, int tnB, int tnC
    | returns bool rlResult
    {
        int lnI, lnJ, lnK, lnVal;


        // Iterate through a sample bit of code to demonstrate the functionality.
        // Note:  The breakN statements work anywhere a normal break would work,
        //        it just does multiple at one time.
        for (lnI = 0; lnI < tnA; ++lnI)
        {
            for (lnJ = 0; lnJ < tnB; ++lnJ)
            {
                for (lnK = 0; lnK = tnC; ++lnK)
                {
                    lnVal = something[lnI][lnJ][lnK];
                    if (lnVal == 3)
                    {
                        // Break out to "here1" below
                        break;

                    } else if (lnVal == 2) {
                        // Break out to "here2" below
                        break2;
                        // Same as if you had a break here, and then a test for some flag, and a second break

                    } else if (lnVal == 3) {
                        // Break out to "here3" below
                        break3;
                        // Same as if you had a break here, and then a test for some flag, and a second break,
                        // and another test for another flag, and a third break
                    }
                }
                // here1
            }
            // here2
        }
        // here3
    }

For sbreak; and sbreakout; see here:

    function sample_sbreak
    | params int tnA, int tnB, int tnC
    | returns bool rlResult
    {
        if (glProcessing)
        {
            if outer (tnA > 2)
            {
                // Make sure b is in range
                if (tnB > 3)
                    sbreak;    // Exit out to a point past the if (tnA > 2) {..} block

                // The following is just an anonymous scope block
                {
                    switch (tnB)
                    {
                        case 0:
                            sbreak;    // Leaves out past the anonymous {..} scope

                        case 1:
                        case 2:
                        case 3:
                            break;

                        default:
                            // Unexpected input
                            return(false);
                    }
                    // Any code here executes only for cases 1,2,3
                }

                // Iterate until we're exhausted
                while (tnC > 0)
                {
                    lnResult = test_something(tnA, tnB, tnC);
                    if (lnResult > 5)
                    {
                        sbreakout;      // Exit all the way out past the if (glProcessing) {..} block

                    } else if (lnResult > 3) {
                        sbreak outer;   // Exit out past the named block called "outer"
                    }

                    // Decrease for next iteration
                    --tnC;
                }
            }
            // Code continues here after the outer break
            return(true);
        }

        // If we get here, we did not process
        return(false);
    }

Thank you,
Rick C. Hodgin

Reply all
Reply to author
Forward
0 new messages