{"id":"ocode-conditional","model_id":"O if","name":"LinuxCNC O-code Conditional","summary":"The O-code conditional is a flow-control block in LinuxCNC NC programs. A group of statements shares one O-number, begins with if, may include elseif and else sections, and ends with endif. The interpreter executes the first branch whose condition is true; if no if or elseif condition is true, it executes the else statements.","study_notes":["O codes use the letter O, not the number zero, as the first character; lowercase o is easier to distinguish from 0.","The same O-number must be used for the if, any elseif or else, and the endif in one conditional group.","Using the same number for more than one block, other words on a line with an O-word, or comments on a line with an O-word has undefined behavior.","When an if condition is false, elseif conditions are evaluated in order until one is true; if none is true, the else statements execute.","When a condition evaluates true, no further conditions in that group are evaluated.","Labels on if, else, elseif, or endif that do not point to a matching block cause an error and abort the interpreter.","Conditional examples use bracketed expressions such as [#31 EQ 3] and [#2 GT 5]."],"safety_notes":[],"sources":[{"url":"https://linuxcnc.org/docs/html/gcode/o-code.html#ocode:conditional","title":"O Codes","accessed":"2026-10-26"}],"verification":{"status":"source_checked","checked_at":"2026-10-26","values":7,"method":"llm_source_check"},"updated_at":"2026-10-26","type":"instruction","spec":{"language":"gcode","code":"if","group":"Conditional","syntax":"Onnn if [condition] ... Onnn elseif [condition] ... Onnn else ... Onnn endif","parameters":[{"name":"O-number","description":"Number used after O; the same number must be used for the if, any elseif or else, and endif statements in the group."},{"name":"condition","description":"Expression in square brackets after if or elseif; evaluated to true or false to choose the branch."}],"dialect":"LinuxCNC","related":[],"standards":[]},"url":"https://machineschema.com/instruction/ocode-conditional","license":"https://creativecommons.org/licenses/by/4.0/"}