Bird
Raised Fist0
CNC Programmingscripting~20 mins

Subprogram for repeated patterns in CNC Programming - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Subprogram Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of a subprogram call with parameters
What will be the tool position output after running this CNC subprogram call?
CNC Programming
O1000 (Main program)
G0 X0 Y0
M98 P2000 L3
M30

O2000 (Subprogram)
G1 X[#1*10] Y[#1*5] F100
M99
AThe tool moves to X30 Y15 after 3 calls
BThe tool moves to X10 Y5 after 3 calls
CThe tool moves to X20 Y10 after 3 calls
DThe tool stays at X0 Y0
Attempts:
2 left
💡 Hint
Check how parameters are passed to subprograms in CNC code.
📝 Syntax
intermediate
1:30remaining
Identify the syntax error in subprogram call
Which option contains a syntax error in calling a subprogram with repetition?
CNC Programming
M98 P3000 L5
AM98 P3000 L5
BM98 P3000 L
CM98 P3000
DM98 L5 P3000
Attempts:
2 left
💡 Hint
Look for missing values after letters in the command.
🚀 Application
advanced
2:30remaining
Using subprograms to drill multiple holes
You want to drill 4 holes spaced 20mm apart on the X-axis starting at X0 Y0. Which subprogram call and main program combination will correctly drill all holes?
CNC Programming
O1000 (Main program)
G0 X0 Y0
M98 P2000 L4
M30

O2000 (Subprogram)
G81 X[#1] Y0 Z-5 R1 F75
M99
AMain program calls M98 P2000 L1 with #1 = 0, 20, 40, 60
BMain program calls M98 P2000 L4 with #1 = 0, 20, 40, 60
CMain program calls M98 P2000 L4 with #1 = 0 only
DMain program calls M98 P2000 L4 with #1 = 20 only
Attempts:
2 left
💡 Hint
How do you pass different parameters for each repetition in CNC subprogram calls?
🔧 Debug
advanced
2:30remaining
Debugging unexpected tool position after subprogram call
After running this CNC program, the tool does not move as expected. What is the cause?
CNC Programming
O1000
G0 X0 Y0
#100=10
M98 P2000 L3
M30

O2000
G1 X[#100*#1] Y0 F100
M99
AParameter #1 is not set, so #100*#1 is zero
BVariable #100 cannot be used in subprogram
CM98 cannot be used with L parameter
DG1 command is invalid inside subprogram
Attempts:
2 left
💡 Hint
Check how parameters and variables are used inside subprograms.
🧠 Conceptual
expert
3:00remaining
Effect of nested subprogram calls with repetition
Consider a main program calling subprogram O2000 with L2, and O2000 calls subprogram O3000 with L3. How many times will O3000 run?
CNC Programming
O1000
M98 P2000 L2
M30

O2000
M98 P3000 L3
M99

O3000
G1 X10 Y10 F100
M99
AO3000 runs 6 times
BO3000 runs 3 times
CO3000 runs 2 times
DO3000 runs 1 time
Attempts:
2 left
💡 Hint
Multiply the repetition counts of nested calls.

Practice

(1/5)
1. What is the main purpose of using a subprogram in CNC programming?
easy
A. To stop the machine immediately
B. To speed up the machine spindle
C. To change the tool automatically
D. To repeat a set of instructions multiple times without rewriting them

Solution

  1. Step 1: Understand subprogram concept

    Subprograms are blocks of code that can be reused multiple times in CNC programming.
  2. Step 2: Identify main purpose

    They help avoid rewriting the same instructions repeatedly, making code shorter and easier to manage.
  3. Final Answer:

    To repeat a set of instructions multiple times without rewriting them -> Option D
  4. Quick Check:

    Subprograms repeat code = D [OK]
Hint: Subprograms repeat code blocks to save writing [OK]
Common Mistakes:
  • Confusing subprograms with tool changes
  • Thinking subprograms control spindle speed
  • Assuming subprograms stop the machine
2. Which of the following is the correct syntax to call a subprogram numbered 100 in CNC code?
easy
A. M99 P100
B. M98 P100
C. M100 P98
D. M98 L100

Solution

  1. Step 1: Recall subprogram call command

    M98 is the standard command to call a subprogram in CNC programming.
  2. Step 2: Match syntax with subprogram number

    The correct syntax is M98 followed by P and the subprogram number, e.g., M98 P100.
  3. Final Answer:

    M98 P100 -> Option B
  4. Quick Check:

    Call subprogram = M98 P[number] [OK]
Hint: Use M98 P[number] to call subprograms [OK]
Common Mistakes:
  • Using M99 to call instead of return
  • Swapping M98 and M99 commands
  • Using L instead of P for subprogram number
3. Given the following CNC code snippet, what will be the output movement commands executed?
O1000;
G01 X10 Y10 F100;
M99;

N10 M98 P1000 L3;
M30;
medium
A. Moves to X10 Y10 three times in a row
B. Moves to X10 Y10 once only
C. Moves to X10 Y10 infinitely
D. No movement commands executed

Solution

  1. Step 1: Understand subprogram call with repetition

    M98 P1000 L3 calls subprogram 1000 three times in a row.
  2. Step 2: Analyze subprogram content

    Subprogram 1000 moves the tool to X10 Y10 with feedrate 100, then returns with M99.
  3. Final Answer:

    Moves to X10 Y10 three times in a row -> Option A
  4. Quick Check:

    M98 P1000 L3 repeats subprogram 3 times = C [OK]
Hint: M98 with L repeats subprogram calls multiple times [OK]
Common Mistakes:
  • Ignoring the L3 repeat count
  • Confusing M99 as a stop command
  • Assuming infinite loop without L parameter
4. Identify the error in this CNC subprogram call:
O2000;
G01 X20 Y20 F150;
M99;

N20 M98 P2000 L0;
M30;
medium
A. M99 should be M98 inside subprogram
B. P2000 is invalid subprogram number
C. L0 causes no repetition, so subprogram never runs
D. Missing G00 command before M98

Solution

  1. Step 1: Check repetition count in subprogram call

    L0 means repeat zero times, so the subprogram is not executed at all.
  2. Step 2: Confirm other commands are correct

    M99 is correct to return from subprogram, P2000 is valid, and G00 is not mandatory before M98.
  3. Final Answer:

    L0 causes no repetition, so subprogram never runs -> Option C
  4. Quick Check:

    L0 means zero repeats = B [OK]
Hint: L0 means no repeats, so subprogram won't run [OK]
Common Mistakes:
  • Thinking M99 is wrong inside subprogram
  • Assuming P2000 is invalid
  • Believing G00 is required before M98
5. You want to drill 5 holes spaced 10mm apart along the X-axis starting at X0 Y0 using a subprogram. Which code snippet correctly uses a subprogram with a loop to achieve this?
hard
A.
O3000;
G81 X#1 Y0 Z-5 R1 F100;
M99;

N30 G91;
M98 P3000 L5;
M30;
B.
O3000;
G81 X0 Y0 Z-5 R1 F100;
M99;

N30 G90;
M98 P3000 L5;
M30;
C.
O3000;
G81 X10 Y0 Z-5 R1 F100;
M99;

N30 G91;
M98 P3000 L5;
M30;
D.
O3000;
G81 X#1 Y0 Z-5 R1 F100;
M30;

N30 G91;
M98 P3000 L5;
M30;

Solution

  1. Step 1: Understand incremental positioning for spacing

    G91 sets incremental mode, so each call moves relative to last position, spacing holes 10mm apart.
  2. Step 2: Check subprogram and loop usage

    Subprogram O3000 uses G81 drilling cycle with X#1 (variable), M99 returns correctly, and M98 P3000 L5 calls it 5 times.
  3. Final Answer:

    Option A correctly uses incremental mode, subprogram, and loop for 5 holes spaced 10mm apart -> Option A
  4. Quick Check:

    Incremental + M98 with L5 = 5 spaced holes [OK]
Hint: Use G91 for incremental moves and M98 L5 to repeat 5 times [OK]
Common Mistakes:
  • Using G90 (absolute) instead of G91 (incremental)
  • Forgetting M99 to return from subprogram
  • Using M30 inside subprogram instead of M99
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