O-code Looping

O-code looping is a flow-control instruction in NC programs that repeats a group of blocks while a condition is true. It supports while/endwhile loops, which test the condition before each iteration, and do/while loops, which test after each iteration. O-break exits the loop immediately and O-continue skips to the next condition test.

Source checked3/3 values · 2026-10-26

Specification

1 source
Languagegcode
CodeO while
Groupflow control
Syntaxo<number> while [condition] ... o<number> endwhile; o<number> do ... o<number> while [condition]
Dialectrs274ngc

Study notes

  • O-codes use the letter O, not the digit zero, as the first character; lowercase o is recommended because it is easier to distinguish from 0.
  • The while/endwhile form evaluates the condition before running the loop body; the do/while form runs the body first, then evaluates the condition.
  • The O-number labels the loop: the same number appears on the opening while/do and the closing endwhile/while, e.g. o101 while ... o101 endwhile.
  • Inside a while loop, O-break immediately exits the loop, and O-continue skips to the next evaluation of the while condition.
  • Using the same O-number for more than one block, or placing other words or comments on the same line as an O-word, is undefined behavior.
↑↓ navigate↵ openesc close