Bird
Raised Fist0
CNC Programmingscripting~20 mins

G-code program structure in CNC Programming - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
G-code Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this G-code program snippet?
Consider this G-code snippet for a CNC milling machine:
N10 G21
N20 G90
N30 G00 X10 Y10
N40 G01 X20 Y20 F100

What is the position of the tool after line N40 executes?
CNC Programming
N10 G21
N20 G90
N30 G00 X10 Y10
N40 G01 X20 Y20 F100
AThe tool is at absolute position X20 Y20
BThe tool is at relative position X30 Y30
CThe tool is at relative position X20 Y20
DThe tool is at absolute position X10 Y10
Attempts:
2 left
💡 Hint
G90 sets absolute positioning, G00 and G01 move the tool to specified coordinates.
🧠 Conceptual
intermediate
1:30remaining
Which line defines the program start in a typical G-code file?
In a standard G-code program, which line usually marks the start of the main machining commands?
AThe line with M30
BThe line with T1
CThe line with G28
DThe line with G00 or G01 after setup commands
Attempts:
2 left
💡 Hint
Look for the first movement command after setup.
🔧 Debug
advanced
2:00remaining
Identify the error in this G-code snippet
This G-code snippet is intended to move the tool to X50 Y50 and then start cutting:
N10 G90
N20 G01 X50 Y50 F200
N30 G00 X0 Y0
N40 M30

What is the problem with this program?
CNC Programming
N10 G90
N20 G01 X50 Y50 F200
N30 G00 X0 Y0
N40 M30
AThe program lacks a spindle start command (M03 or M04)
BThe feed rate F200 is missing a unit
CG90 should be after M30
DG00 cannot be used after G01
Attempts:
2 left
💡 Hint
Check if the spindle is turned on before cutting moves.
🚀 Application
advanced
1:30remaining
How many lines are in this G-code program excluding comments?
Count the number of executable lines in this G-code program (ignore lines starting with ';' which are comments):
; Program start
N5 G21
N10 G90
; Move to start
N15 G00 X0 Y0
N20 G01 X10 Y10 F150
N25 M05
N30 M30
CNC Programming
; Program start
N5 G21
N10 G90
; Move to start
N15 G00 X0 Y0
N20 G01 X10 Y10 F150
N25 M05
N30 M30
A7
B6
C8
D5
Attempts:
2 left
💡 Hint
Count only lines that do not start with ';'.
🧠 Conceptual
expert
1:00remaining
What is the effect of the M30 command in a G-code program?
In a CNC program, what does the M30 command do when executed?
AStarts the coolant flow
BPauses the program and waits for operator input
CStops the spindle and ends the program, rewinding to start
DMoves the tool to the home position
Attempts:
2 left
💡 Hint
Think about program end and reset commands.

Practice

(1/5)
1. What is the correct way to start a G-code program?
easy
A. Write G90 as the first line
B. Start with the command M30
C. Use G01 to start the program
D. Begin with a program number like O1000

Solution

  1. Step 1: Identify the program start syntax

    G-code programs start with a program number, usually written as O1000 or similar.
  2. Step 2: Understand the role of other commands

    M30 ends the program, G01 and G90 are motion and positioning commands, not start markers.
  3. Final Answer:

    Begin with a program number like O1000 -> Option D
  4. Quick Check:

    Program start = O1000 [OK]
Hint: Program always starts with O-number like O1000 [OK]
Common Mistakes:
  • Confusing M30 as start instead of end
  • Using motion commands as start
  • Skipping program number line
2. Which of the following lines correctly ends a G-code program?
easy
A. G00 X0 Y0
B. O1000
C. M30
D. G90

Solution

  1. Step 1: Identify the program end command

    The command M30 is used to stop and end a G-code program.
  2. Step 2: Differentiate from other commands

    G00 moves the tool, G90 sets positioning mode, and O1000 is a program number, not an end command.
  3. Final Answer:

    M30 -> Option C
  4. Quick Check:

    Program end = M30 [OK]
Hint: Program ends with M30 command [OK]
Common Mistakes:
  • Using motion commands as program end
  • Confusing program number with end command
  • Omitting M30 at program end
3. Given the following G-code snippet, what is the tool's final position?
O1000
G90
G00 X10 Y5
G01 X20 Y15 F100
M30
medium
A. X20 Y15
B. X10 Y5
C. X0 Y0
D. X100 Y100

Solution

  1. Step 1: Trace the tool movements

    G00 X10 Y5 moves the tool rapidly to X=10, Y=5. Then G01 X20 Y15 F100 moves it linearly to X=20, Y=15.
  2. Step 2: Identify final position before program end

    The last position command is G01 X20 Y15, so the tool ends at X=20, Y=15.
  3. Final Answer:

    X20 Y15 -> Option A
  4. Quick Check:

    Last move = X20 Y15 [OK]
Hint: Final position is last coordinate command before M30 [OK]
Common Mistakes:
  • Confusing rapid move (G00) as final position
  • Ignoring linear move (G01)
  • Assuming start position is final
4. Identify the error in this G-code program snippet:
O2000
G01 X10 Y10
G90
M30
medium
A. G90 should come before G01 for positioning mode
B. M30 is used incorrectly
C. Missing program start number
D. No error, program is correct

Solution

  1. Step 1: Check command order for positioning

    G90 sets absolute positioning and should be set before any move commands like G01.
  2. Step 2: Analyze the given order

    The program moves with G01 before setting G90, which can cause unexpected positioning behavior.
  3. Final Answer:

    G90 should come before G01 for positioning mode -> Option A
  4. Quick Check:

    Set positioning mode before moves [OK]
Hint: Set G90 before moves to avoid positioning errors [OK]
Common Mistakes:
  • Placing G90 after move commands
  • Ignoring command order importance
  • Assuming M30 ends program incorrectly
5. You want to write a G-code program that sets absolute positioning, moves the tool to X=50 Y=50 at feed rate 200, then ends the program. Which is the correct structure?
hard
A.
O3000
G01 X50 Y50 F200
G90
M30
B.
O3000
G90
G01 X50 Y50 F200
M30
C.
G90
O3000
G01 X50 Y50 F200
M30
D.
O3000
M30
G90
G01 X50 Y50 F200

Solution

  1. Step 1: Confirm program start and positioning

    The program must start with a program number O3000 and set absolute positioning G90 before moves.
  2. Step 2: Check move command and program end

    G01 X50 Y50 F200 moves the tool at feed rate 200, and M30 ends the program properly.
  3. Final Answer:

    O3000 G90 G01 X50 Y50 F200 M30 -> Option B
  4. Quick Check:

    Start with O-number, set G90, move, then M30 [OK]
Hint: Start with O-number, set G90, move, then M30 to end [OK]
Common Mistakes:
  • Placing M30 before moves
  • Setting G90 after moves
  • Starting without program number
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