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

🖥 Pongy game

This program is a port (and slight mod) of the QB64pe program by SierraKen.  (SierraKen's program shared with the QB64pe community in th...