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

🖥 Fan Dance

This is a port and mod of a SpecBAS program by ZXDunny. Run the program View the source code And, a "less is more?" version: Run t...