Bird
Raised Fist0
CNC Programmingscripting~5 mins

Conditional statements (IF-THEN) in CNC Programming - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is the purpose of an IF-THEN statement in CNC programming?
An IF-THEN statement checks a condition and runs a set of commands only if that condition is true. It helps the machine make decisions during operation.
Click to reveal answer
beginner
How does an IF-THEN statement improve CNC program flexibility?
It allows the program to react to different situations, like stopping if a tool is worn or changing speed based on material type, making the process smarter.
Click to reveal answer
intermediate
Example: What does this code do?
IF [#100 EQ 1] THEN
GOTO 100
ENDIF
It checks if variable #100 equals 1. If yes, the program jumps to line 100. If not, it continues normally.
Click to reveal answer
beginner
What happens if the condition in an IF-THEN statement is false?
The commands inside the IF-THEN block are skipped, and the program continues with the next instructions after ENDIF.
Click to reveal answer
beginner
Why is it important to use ENDIF in CNC IF-THEN statements?
ENDIF marks the end of the conditional block, so the machine knows where the IF-THEN commands stop and can continue the program correctly.
Click to reveal answer
In CNC programming, what does IF [#101 GT 5] THEN do?
ARuns commands if variable #101 equals 5
BRuns commands if variable #101 is less than 5
CRuns commands if variable #101 is greater than 5
DRuns commands if variable #101 is not equal to 5
What keyword ends an IF-THEN block in CNC programming?
AENDIF
BEND
CSTOP
DEXIT
What happens if the IF condition is false?
ACommands inside IF-THEN are skipped
BProgram stops immediately
CProgram jumps to start
DMachine errors out
Which of these is a valid IF condition in CNC?
AIF #200 = 0 THEN
BIF [#200 EQ 0] THEN
CIF #200 == 0 THEN
DIF #200 != 0 THEN
Why use IF-THEN in CNC programs?
ATo reset the machine
BTo speed up the machine
CTo stop the program permanently
DTo make decisions based on conditions
Explain how an IF-THEN statement works in CNC programming and why it is useful.
Think about how machines can choose different actions.
You got /4 concepts.
    Describe the syntax of a basic IF-THEN block in CNC and the role of ENDIF.
    Remember the keywords and structure.
    You got /4 concepts.

      Practice

      (1/5)
      1. What does an IF-THEN statement do in CNC programming?
      easy
      A. It repeats a set of commands multiple times.
      B. It stops the machine immediately.
      C. It defines the speed of the machine.
      D. It makes the program choose actions based on conditions.

      Solution

      1. Step 1: Understand the purpose of IF-THEN

        IF-THEN checks a condition and runs commands only if the condition is true.
      2. Step 2: Compare with other options

        Repeating commands is done by loops, speed is set by other commands, and stopping is a different command.
      3. Final Answer:

        It makes the program choose actions based on conditions. -> Option D
      4. Quick Check:

        IF-THEN controls flow based on conditions [OK]
      Hint: IF-THEN means "if this, then do that" [OK]
      Common Mistakes:
      • Confusing IF-THEN with loops
      • Thinking IF-THEN sets machine speed
      • Assuming IF-THEN stops the machine
      2. Which of the following is the correct syntax for an IF statement in CNC programming?
      easy
      A. WHEN condition DO commands END
      B. IF (condition) { commands }
      C. IF [condition] THEN commands ENDIF
      D. if condition: commands

      Solution

      1. Step 1: Identify CNC IF syntax

        CNC uses IF [condition] THEN ... ENDIF structure.
      2. Step 2: Check other options

        Options B and C use programming languages like C or Python syntax, A is not standard CNC syntax.
      3. Final Answer:

        IF [condition] THEN commands ENDIF -> Option C
      4. Quick Check:

        CNC IF syntax uses THEN and ENDIF [OK]
      Hint: Look for THEN and ENDIF keywords in CNC IF syntax [OK]
      Common Mistakes:
      • Using parentheses or braces like other languages
      • Omitting THEN or ENDIF keywords
      • Confusing IF with WHEN or DO
      3. What will be the output of this CNC code snippet?
      IF #100 GT 50 THEN
        #101 = 1
      ELSE
        #101 = 0
      ENDIF
      PRINT #101
      Assuming variable #100 is 60.
      medium
      A. 0
      B. 1
      C. Syntax Error
      D. No output

      Solution

      1. Step 1: Evaluate the condition #100 GT 50

        #100 is 60, which is greater than 50, so condition is true.
      2. Step 2: Determine the assigned value to #101

        Since condition is true, #101 is set to 1, then printed.
      3. Final Answer:

        1 -> Option B
      4. Quick Check:

        60 > 50 is true, so #101 = 1 [OK]
      Hint: Check condition truth to find which branch runs [OK]
      Common Mistakes:
      • Confusing GT (greater than) with LT (less than)
      • Ignoring ELSE branch
      • Assuming syntax error due to ELSE
      4. Identify the error in this CNC IF statement:
      IF #200 EQ 10
        G01 X100 Y100
      ENDIF
      medium
      A. Missing THEN keyword after condition
      B. Incorrect variable name #200
      C. Missing ENDIF keyword
      D. G01 command is invalid inside IF

      Solution

      1. Step 1: Check IF statement syntax

        CNC IF requires THEN after the condition, missing here.
      2. Step 2: Verify other parts

        Variable name is valid, ENDIF is present, G01 is valid command inside IF.
      3. Final Answer:

        Missing THEN keyword after condition -> Option A
      4. Quick Check:

        IF must have THEN before commands [OK]
      Hint: IF condition must be followed by THEN [OK]
      Common Mistakes:
      • Forgetting THEN after IF condition
      • Thinking ENDIF is missing
      • Assuming commands can't be inside IF
      5. You want the CNC machine to move to X=50 only if the tool number (#1) is 3 or higher. Which IF statement correctly does this?
      hard
      A. IF #1 GE 3 THEN G01 X50 ENDIF
      B. IF #1 GT 3 THEN G01 X50 ENDIF
      C. IF #1 LE 3 THEN G01 X50 ENDIF
      D. IF #1 EQ 3 THEN G01 X50 ENDIF

      Solution

      1. Step 1: Understand the condition "3 or higher"

        This means #1 is greater than or equal to 3 (GE 3).
      2. Step 2: Check each option's condition

        IF #1 GE 3 THEN G01 X50 ENDIF uses GE (greater or equal), B uses GT (greater than) which excludes 3, C uses LE (less or equal), D uses EQ (equal only).
      3. Final Answer:

        IF #1 GE 3 THEN G01 X50 ENDIF -> Option A
      4. Quick Check:

        GE means "3 or higher" [OK]
      Hint: Use GE for "greater or equal" conditions [OK]
      Common Mistakes:
      • Using GT excludes the value 3
      • Using LE or EQ does not cover all values 3 or higher
      • Confusing GE with GT
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard