{"id":"ocode-looping","model_id":"O-code Looping","name":"O-code Looping","summary":"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.","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."],"safety_notes":[],"sources":[{"url":"https://linuxcnc.org/docs/html/gcode/o-code.html#ocode:looping","title":"O Codes","accessed":"2026-10-26"}],"verification":{"status":"source_checked","checked_at":"2026-10-26","values":3,"method":"llm_source_check"},"updated_at":"2026-10-26","type":"instruction","spec":{"language":"gcode","code":"O while","group":"flow control","syntax":"o<number> while [condition] ... o<number> endwhile; o<number> do ... o<number> while [condition]","parameters":[],"dialect":"rs274ngc","related":[],"standards":[]},"url":"https://machineschema.com/instruction/ocode-looping","license":"https://creativecommons.org/licenses/by/4.0/"}