This article is currently available in English. Your interface language stays selected.

03 · BUILD A PATTERN

Repeat an idea with FOR / NEXT

Understand a BASIC FOR / NEXT loop, its counter, and how repeated statements create a simple pattern.

Try these BASIC examples in the Web IDE Terminal.

Say it three times

A FOR loop repeats a block of statements. This counter starts at 1, increases by 1 after each pass, and stops after the pass where it reaches 3.

BASIC
FOR idea = 1 TO 3
    PRINT "Make something cool."
NEXT idea
EXPECTED OUTPUT
Make something cool.
Make something cool.
Make something cool.

Use the counter

The loop variable is available inside the block. Print it to see the progression.

BASIC
FOR number = 1 TO 5
    PRINT number * number
NEXT number

This produces the numeric values 1, 4, 9, 16, and 25. Indentation helps people see the block; the BASIC keywords define its structure.

Keep an escape route

Not every program stops when you expect it to. Use Stop or Ctrl+C to interrupt running code, including operations waiting for input or a device.

Other supported loops include WHILE/WEND and DO/LOOP. Detailed loop edge cases belong to the tested language reference.

Turn repetition into an interaction

Try printing the same message five times. Next, ask the person running the program for input.

← Back to Learn