Wednesday, October 26, 2022

❇ FOR NEXT: multiple controlVariables.

BAM supports (with nested FOR loops) multiple controlVariables in one NEXT statement for all of the FOR statements.

So now, we are not limited to:

for i = 1 to 2

    for j = 1 to 21 step 20

        locate i, j

        print "hello world!"

    next j

next i

We can instead do this:

for i = 1 to 2

    for j = 1 to 21 step 20

        locate i, j

        print "hello world!"

next j, i


Although it is not necessary to specify controlVariables with the NEXT statement, be aware that each FOR statement then requires a dedicated NEXT.  For example:

for i = 1 to 2

    for j = 1 to 21 step 20

        locate i, j

        print "hello world!"

    next

next

OR:

for i = 1 to 2

    for j = 1 to 21 step 20

        locate i, j

        print "hello world!"

next : next

Personally, I prefer the approach in the first example.  A little bit verbose but very clear.

No comments:

Post a Comment

🖥 Flower Tesselation: Testing DRAW and recursive SUB's

This BAM program inspired by Richard Russell's "Flower-like tesselation" BBC BASIC program posted on Facebook . Created in ord...