Skip to main content

For Construct, continued

There's more to For. You can specify the counter argument form of For without an ending value, which would normally result in an infinite loop. But by placing a Quit within the code block, you terminate the For. This last concept bears repeating: a Quit command within a For construct terminates the For. This approach gives you a counter that you can use within the repetitions, but allows you to control the For using a condition that is not based on the counter's value. If you don't need a counter at all, you can use an argumentless For.

Note that the first For below contains an If construct.

The forexample example, continued:

Capital of MA? BAHSTON
Capital of MA? WORCESTER
Capital of MA? SPRINGFIELD
Capital of MA? BOSTON...did it in 4 tries

Know what? WHAT?   That's what!
Know what? WHAT?   That's what!
Know what? WHAT?   That's what!
Know what? NO!
SAMPLES>

Part 2 of the forexample.mac code:

    for i = 1:1 {
    read !, "Capital of MA? ", a
    if a = "BOSTON" {
        write "...did it in ", i, " tries"
        quit
        }
    }
    write !!
    for {
        read !, "Know what? ", wh
        quit:(wh = "NO!")
        write "   That's what!"
    }
FeedbackOpens in a new tab