{"id":1880,"date":"2026-12-03T15:57:12","date_gmt":"2026-12-03T13:57:12","guid":{"rendered":"https:\/\/macromillcnc.com\/2026\/12\/03\/fanuc-macro-while-vs-if\/"},"modified":"2026-12-03T15:57:12","modified_gmt":"2026-12-03T13:57:12","slug":"fanuc-macro-while-vs-if","status":"publish","type":"post","link":"https:\/\/macromillcnc.com\/2026\/12\/03\/fanuc-macro-while-vs-if\/","title":{"rendered":"WHILE vs IF in FANUC macros: a lesson on repeating and deciding"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This FANUC macro lesson is about the difference between WHILE and IF. Both let a program decide something, and beginners often mix them up. By the end you will know which one repeats, which one decides once, how to write each, and how the two work together in one real MacroMill macro.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can step through every example in the <a href=\"https:\/\/macromillcnc.com\/#mmx-vmc-title\">MacroMill FANUC VMC simulator<\/a>, the FANUC VMC Advanced Control Suite, and watch the variables change line by line. Yes, programs and macros you write and test in a MacroMill simulator can be saved or exported and run on a real CNC machine, after a normal prove-out with single block, reduced rapids and a dry run.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The difference between WHILE and IF in one minute<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>IF is a one-time decision.<\/strong> The control reaches the IF, tests the condition once, and either runs what follows or skips it. Then it carries on down the program. It never goes back.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>WHILE is a repeat.<\/strong> The control tests the condition before every pass. While it is true, it runs every block between WHILE and the matching END, jumps back to the WHILE and tests again. When the test is false, it jumps to the block after END and leaves the loop.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So the short answer is: use IF to choose, and use WHILE to repeat. If you want a block to run once or not at all, that is IF. If you want it to run again and again until a number reaches a limit, that is WHILE.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to write IF<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">FANUC Macro B has two forms of IF. IF THEN runs one statement when the condition is true. IF GOTO jumps to a sequence number when the condition is true.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>IF [#101 GT 0] THEN #102 = 1\nIF [#101 LE 0] GOTO 100<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the first line, #102 becomes 1 only when #101 is greater than 0. If it is not, the control ignores the statement and moves to the next block. In the second line, a true condition sends the program to the block with N100, skipping everything in between. A false condition does nothing and the next block runs. The code above shows the pattern only; the real examples come later.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to write WHILE<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">WHILE needs a condition, a DO number and a matching END with the same number.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#101 = 0\nWHILE [#101 LT 4] DO1\n(blocks that repeat)\n#101 = #101 + 1\nEND1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The test #101 LT 4 is made before each pass, so the body runs for #101 = 0, 1, 2 and 3, and the loop leaves when #101 reaches 4. The line that adds 1 is what moves the counter toward the exit. Leave it out and the condition stays true forever. We walk through that mistake in <a href=\"https:\/\/macromillcnc.com\/2026\/11\/10\/fanuc-macro-while-loop\/\">How a FANUC macro WHILE loop works<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1920\" height=\"1080\" data-attachment-id=\"1672\" data-permalink=\"https:\/\/macromillcnc.com\/fanuc-macro-while-loop-step-through\/\" data-orig-file=\"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/fanuc-macro-while-loop-step-through.jpg?fit=1920%2C1080&amp;ssl=1\" data-orig-size=\"1920,1080\" data-comments-opened=\"1\" data-image-title=\"FANUC macro WHILE loop step-through\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;Illustrative walkthrough with #101=4 and a +1 update: four true passes, then exit.&lt;\/p&gt;\n\" data-large-file=\"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/fanuc-macro-while-loop-step-through.jpg?fit=1024%2C576&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/fanuc-macro-while-loop-step-through.jpg?resize=1920%2C1080&#038;ssl=1\" alt=\"WHILE loop step-through in a FANUC macro on the MacroMill simulator: the test is true for counters 0 to 3 and false at 4\" class=\"wp-image-1672\" srcset=\"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/fanuc-macro-while-loop-step-through.jpg?w=1920&amp;ssl=1 1920w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/fanuc-macro-while-loop-step-through.jpg?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/fanuc-macro-while-loop-step-through.jpg?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/fanuc-macro-while-loop-step-through.jpg?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/fanuc-macro-while-loop-step-through.jpg?resize=1536%2C864&amp;ssl=1 1536w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/fanuc-macro-while-loop-step-through.jpg?resize=1320%2C743&amp;ssl=1 1320w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/fanuc-macro-while-loop-step-through.jpg?resize=600%2C338&amp;ssl=1 600w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption class=\"wp-element-caption\">The MacroMill simulator steps a WHILE loop: counters 0 to 3 are true, counter 4 is false and the loop exits. Illustrative walkthrough with #101 = 4.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">The comparison operators: EQ, NE, GT, LT, GE and LE<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Both IF and WHILE use the same six comparison words inside square brackets.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>EQ<\/strong>: equal to<\/li>\n\n<li><strong>NE<\/strong>: not equal to<\/li>\n\n<li><strong>GT<\/strong>: greater than<\/li>\n\n<li><strong>LT<\/strong>: less than<\/li>\n\n<li><strong>GE<\/strong>: greater than or equal to<\/li>\n\n<li><strong>LE<\/strong>: less than or equal to<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The boundary is the part that catches people out. WHILE [#101 LT 4] runs four times from a start of 0. WHILE [#101 LE 4] runs five times. One letter changes the number of passes, so choose LT or LE on purpose and test it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">DO1, DO2 and DO3: nesting loops<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can put one WHILE inside another. FANUC gives you three nesting levels, DO1 to DO3, and each loop closes with its own number: END1, END2 or END3. The numbers must match and the loops must nest cleanly, with the inner loop finished before the outer one ends.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The bolt hole circle macro below does exactly this. DO1 loops over the holes, and DO2 inside it loops over the depth steps of one hole.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A real example: WHILE and IF working together<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is the depth loop from MacroMill\u2019s bolt hole circle lesson, program O9011. It cuts each hole with a helical path, one quarter turn at a time. Here are the lines from the loop.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#153 = 0. (HELIX ANGLE)\n#154 = 0. (DEPTH)\nWHILE [#154 LT #110] DO2\n#154 = #154 + #114\nIF [#154 GT #110] THEN #154 = #110\n#155 = #153\n#153 = #153 + #145 * 90.\nG#144 X[#151+#142*COS[#153]] Y[#152+#142*SIN[#153]] Z[#111-#154] I[-#142*COS[#155]] J[-#142*SIN[#155]] F#119\nEND2<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this lesson #110 is the hole depth, 39, and #114 is the depth per quarter turn, 0.75. Here is what each part does.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>WHILE [#154 LT #110] DO2<\/strong> repeats the quarter turns. It keeps going while the depth so far, #154, is less than the hole depth, #110.<\/li>\n\n<li><strong>#154 = #154 + #114<\/strong> adds one more step of depth on every pass. This is the line that moves the loop toward its exit.<\/li>\n\n<li><strong>IF [#154 GT #110] THEN #154 = #110<\/strong> is the decision. If a step would take the depth past the bottom, it clamps #154 to the bottom, so the last pass cannot overshoot.<\/li>\n\n<li><strong>END2<\/strong> jumps back to the WHILE and tests again.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">With a depth of 39 and a step of 0.75, the loop needs 52 quarter turns, and the 52nd lands exactly on Z-39. Because 39 divides evenly by 0.75, the clamp stays quiet in this case. Now change the hole depth to 39.5. The steps no longer divide evenly, and without the IF the last pass would cut past the bottom. With the IF, it stops exactly at the depth you asked for. That is the power of using them together: WHILE does the repeating, and IF protects the edge.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1920\" height=\"1080\" data-attachment-id=\"1878\" data-permalink=\"https:\/\/macromillcnc.com\/while-if-fanuc-macro-depth-loop\/\" data-orig-file=\"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/while-if-fanuc-macro-depth-loop.jpg?fit=1920%2C1080&amp;ssl=1\" data-orig-size=\"1920,1080\" data-comments-opened=\"1\" data-image-title=\"WHILE and IF in a FANUC macro on the MacroMill simulator\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;The O9011 depth loop: WHILE repeats the quarter turns and IF clamps the last pass to the bottom.&lt;\/p&gt;\n\" data-large-file=\"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/while-if-fanuc-macro-depth-loop.jpg?fit=1024%2C576&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/while-if-fanuc-macro-depth-loop.jpg?resize=1920%2C1080&#038;ssl=1\" alt=\"WHILE and IF in a FANUC macro on the MacroMill simulator: O9011 shows WHILE[#154LT#110]DO2, an IF clamp and END2\" class=\"wp-image-1878\" srcset=\"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/while-if-fanuc-macro-depth-loop.jpg?w=1920&amp;ssl=1 1920w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/while-if-fanuc-macro-depth-loop.jpg?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/while-if-fanuc-macro-depth-loop.jpg?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/while-if-fanuc-macro-depth-loop.jpg?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/while-if-fanuc-macro-depth-loop.jpg?resize=1536%2C864&amp;ssl=1 1536w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/while-if-fanuc-macro-depth-loop.jpg?resize=1320%2C743&amp;ssl=1 1320w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/while-if-fanuc-macro-depth-loop.jpg?resize=600%2C338&amp;ssl=1 600w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption class=\"wp-element-caption\">The O9011 depth loop in the MacroMill simulator: WHILE repeats the quarter turns and IF clamps the last pass to the bottom.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The screenshot shows the same lines in the simulator, with the variables beside them. On pass 6, #154 is 6 \u00d7 0.75 = 4.5 and the angle #153 is 540 degrees, so X = 100 + 14 \u00d7 COS 540 = 86 and Z = -4.5. You can read the program and see exactly why it moved there. For the full walk-through of this macro, read <a href=\"https:\/\/macromillcnc.com\/2026\/11\/14\/bolt-hole-circle-and-a-axis-rope-groove\/\">the bolt hole circle and A-axis rope groove lessons<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">IF on its own: choosing a direction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Not every decision needs a loop. In the MacroMill rope groove lesson, program O9010 cuts the groove level by level. It must change direction on every second level, so the passes run left to right, then right to left. That is a serpentine path, and it is a single IF.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#157 = 1\nIF [[#150-2*FIX[#150\/2]]EQ0] THEN #157 = -1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">#150 is the depth level. The expression #150 &#8211; 2 \u00d7 FIX[#150 \/ 2] is the remainder after dividing the level by 2, so it is 0 on even levels and 1 on odd levels. #157 starts at 1. On an even level the IF sets it to -1, which flips the side the passes start from. The IF runs once for each level and makes one choice.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1920\" height=\"1080\" data-attachment-id=\"1879\" data-permalink=\"https:\/\/macromillcnc.com\/if-then-fanuc-macro-passes-per-level\/\" data-orig-file=\"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/if-then-fanuc-macro-passes-per-level.jpg?fit=1920%2C1080&amp;ssl=1\" data-orig-size=\"1920,1080\" data-comments-opened=\"1\" data-image-title=\"IF THEN lines in a FANUC macro on the MacroMill simulator\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;The O9010 program panel: three IF&amp;#8230;THEN decisions, with the serpentine direction line highlighted.&lt;\/p&gt;\n\" data-large-file=\"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/if-then-fanuc-macro-passes-per-level.jpg?fit=1024%2C576&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/if-then-fanuc-macro-passes-per-level.jpg?resize=1920%2C1080&#038;ssl=1\" alt=\"IF THEN lines in a FANUC macro on the MacroMill simulator, with the #157 serpentine direction IF highlighted\" class=\"wp-image-1879\" srcset=\"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/if-then-fanuc-macro-passes-per-level.jpg?w=1920&amp;ssl=1 1920w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/if-then-fanuc-macro-passes-per-level.jpg?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/if-then-fanuc-macro-passes-per-level.jpg?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/if-then-fanuc-macro-passes-per-level.jpg?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/if-then-fanuc-macro-passes-per-level.jpg?resize=1536%2C864&amp;ssl=1 1536w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/if-then-fanuc-macro-passes-per-level.jpg?resize=1320%2C743&amp;ssl=1 1320w, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/if-then-fanuc-macro-passes-per-level.jpg?resize=600%2C338&amp;ssl=1 600w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption class=\"wp-element-caption\">The O9010 program panel in MacroMill: three IF&#8230;THEN decisions, with the serpentine direction line highlighted.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">IF is also how a macro protects itself. The same rope groove program checks its inputs at the start, and stops with an alarm if something is wrong:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>IF[#100LE0]THEN#3000=1(STOCK DIAMETER MUST BE ABOVE 0)\nIF[#103LE0]THEN#3000=2(PITCH MUST BE ABOVE 0)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Setting #3000 raises a macro alarm and stops the program, so a bad input cannot reach the cutting blocks. This is the kind of check we cover in <a href=\"https:\/\/macromillcnc.com\/2026\/11\/26\/fanuc-macro-mistakes\/\">common FANUC macro mistakes<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When to use WHILE and when to use IF<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Use IF<\/strong> to choose between two outcomes, to set a value only in certain cases, to clamp a number to a limit, or to check an input and raise an alarm.<\/li>\n\n<li><strong>Use WHILE<\/strong> when the same set of blocks must run several times and you can say when it stops: holes in a circle, depth steps, thread passes or tool-wear steps.<\/li>\n\n<li><strong>Use both<\/strong> when a repeat needs guard rails. A WHILE with an IF inside it is the most common pattern in a working macro.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Why WHILE and IF make one macro do the work of many<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Without a loop, a bolt hole circle with 8 holes needs 8 copies of the same blocks, and 52 quarter turns per hole would take hundreds of lines. With WHILE, it is one short loop. Change the hole count or depth in the variables and the same program cuts a different part. With IF, the program adapts to what it is given instead of crashing on a bad value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That is how a macro becomes reusable for any size: WHILE removes the repeated blocks, and IF handles the cases. For more on the idea, see <a href=\"https:\/\/macromillcnc.com\/2026\/11\/19\/cnc-macro-programming-guide\/\">the CNC macro programming guide<\/a> and <a href=\"https:\/\/macromillcnc.com\/2026\/11\/10\/cnc-macros-productivity-write-once\/\">write once, not again<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Try it yourself<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. Which one repeats, WHILE or IF?<\/strong><br>WHILE. It tests before each pass and repeats the blocks up to END. IF decides once and moves on.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. How many times does WHILE [#101 LT 4] DO1 run if #101 starts at 0 and the loop adds 1 each pass?<\/strong><br>Four times, for #101 = 0, 1, 2 and 3. At 4 the test is false and the loop exits.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. What happens if you forget the line that adds to the counter inside the WHILE?<\/strong><br>The condition never becomes false, so the loop never ends. The counter update is what moves the loop toward its exit.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4. What does IF [#154 GT #110] THEN #154 = #110 do in the depth loop?<\/strong><br>If the next step would go deeper than the hole bottom, it sets the depth to the bottom, so the last pass cannot overshoot.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5. What is the difference between LT and LE?<\/strong><br>LT is less than, and LE is less than or equal to. With a counter starting at 0, WHILE [#101 LT 4] runs four times and WHILE [#101 LE 4] runs five.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Practise WHILE and IF in the MacroMill simulator<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Reading about WHILE and IF helps, but you learn them fastest by stepping through them and watching the variables change. The <a href=\"https:\/\/macromillcnc.com\/#mmx-vmc-title\">MacroMill FANUC VMC simulator<\/a> lets you write a macro, run it one block at a time, and see each variable, each test and each toolpath result as it happens. You can break a loop on purpose, fix it, and see the program react, all before you go near a machine. Programs and macros you write and test there can be saved or exported and run on a real CNC machine, after a normal prove-out with single block, reduced rapids and a dry run.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Get the simulator here: <a href=\"https:\/\/payhip.com\/b\/WtAqz\" target=\"_blank\" rel=\"noopener\">MacroMill FANUC VMC Advanced Control Suite on Payhip<\/a>, or see it on <a href=\"https:\/\/macromillcnc.com\/#mmx-vmc-title\">the MacroMill homepage<\/a>. If you have a question about the lesson, write to <a href=\"mailto:info@macromillcnc.online\">info@macromillcnc.online<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For tips and updates, join the MacroMill WhatsApp group: <a href=\"https:\/\/chat.whatsapp.com\/Htae97asBiD14QiwMXjGJA\" target=\"_blank\" rel=\"noopener\">chat.whatsapp.com\/Htae97asBiD14QiwMXjGJA<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>The software is for training and simulation only. Yes, programs and macros you write and test in a MacroMill simulator can be saved or exported and run on a real CNC machine. As with any new program, prove it out first with single block, reduced rapids and a dry run before you cut. Addresses, variable numbers, feeds, speeds, clearances and tool offsets in these examples must be confirmed against your machine, your tooling and your control\u2019s Custom Macro B manual.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>MacroMill<\/strong><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>A FANUC macro lesson on WHILE vs IF: IF decides once, WHILE repeats. See both work together in a real MacroMill depth loop and practise them in the simulator.<\/p>\n","protected":false},"author":279632934,"featured_media":1878,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_seo_llms_txt_always_include":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_wpcom_ai_launchpad_first_post":false,"_jetpack_feature_clip_id":0,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1378],"tags":[],"class_list":["post-1880","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/phcvZP-uk","jetpack-related-posts":[{"id":1852,"url":"https:\/\/macromillcnc.com\/2026\/11\/28\/stop-learning-cnc-on-a-live-machine\/","url_meta":{"origin":1880,"position":0},"title":"Stop learning CNC on a live machine: get job-ready faster","author":"MacroMill","date":"November 28, 2026","format":false,"excerpt":"Learning CNC on a live machine is slow and expensive. See how programmers get job-ready on a MacroMill simulator first, then take the program to the machine.","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/macromillcnc.com\/category\/tutorials\/"},"img":{"alt_text":"MacroMill FANUC CNC simulator all-in-one bundle","src":"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-simulator-all-in-one-bundle.png?fit=1080%2C1080&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-simulator-all-in-one-bundle.png?fit=1080%2C1080&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-simulator-all-in-one-bundle.png?fit=1080%2C1080&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-simulator-all-in-one-bundle.png?fit=1080%2C1080&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-simulator-all-in-one-bundle.png?fit=1080%2C1080&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1827,"url":"https:\/\/macromillcnc.com\/2026\/11\/24\/how-to-choose-a-cnc-simulator\/","url_meta":{"origin":1880,"position":1},"title":"How to choose a CNC simulator for FANUC G-code and macro training","author":"MacroMill","date":"November 24, 2026","format":false,"excerpt":"A practical checklist for how to choose a CNC simulator for FANUC G-code and macro training, and a clear look at where MacroMill\u2019s simulators fit.","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/macromillcnc.com\/category\/tutorials\/"},"img":{"alt_text":"MacroMill VMC simulator for FANUC 0i-MF Plus style controls","src":"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-0i-mf-plus-vmc-simulator.png?fit=1080%2C1080&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-0i-mf-plus-vmc-simulator.png?fit=1080%2C1080&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-0i-mf-plus-vmc-simulator.png?fit=1080%2C1080&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-0i-mf-plus-vmc-simulator.png?fit=1080%2C1080&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-0i-mf-plus-vmc-simulator.png?fit=1080%2C1080&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1836,"url":"https:\/\/macromillcnc.com\/2026\/11\/26\/write-test-and-run-a-fanuc-macro\/","url_meta":{"origin":1880,"position":2},"title":"Write a FANUC macro, test it in MacroMill, then run it on your machine","author":"MacroMill","date":"November 26, 2026","format":false,"excerpt":"Write and test a FANUC Custom Macro B program in a MacroMill simulator, then save or export it and run it on a real CNC machine after a normal prove-out.","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/macromillcnc.com\/category\/tutorials\/"},"img":{"alt_text":"MacroMill VMC simulator for FANUC 0i-MF Plus style controls","src":"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-0i-mf-plus-vmc-simulator.png?fit=1080%2C1080&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-0i-mf-plus-vmc-simulator.png?fit=1080%2C1080&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-0i-mf-plus-vmc-simulator.png?fit=1080%2C1080&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-0i-mf-plus-vmc-simulator.png?fit=1080%2C1080&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-0i-mf-plus-vmc-simulator.png?fit=1080%2C1080&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1874,"url":"https:\/\/macromillcnc.com\/2026\/12\/03\/fanuc-probing-g31-lesson\/","url_meta":{"origin":1880,"position":3},"title":"A FANUC probing lesson: G31 skip, stylus radius and a custom cycle","author":"MacroMill","date":"December 3, 2026","format":false,"excerpt":"A FANUC probing lesson: work through a G31 skip in X, compensate the stylus radius, then build a custom cycle that finds a slot centre and updates G54.","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/macromillcnc.com\/category\/tutorials\/"},"img":{"alt_text":"MacroMill VMC Pro FANUC VMC simulator, probing edition, showing an OMP60-style probe measuring a boss in 3D graphics","src":"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/01_cover.png?fit=1024%2C1024&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/01_cover.png?fit=1024%2C1024&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/01_cover.png?fit=1024%2C1024&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/01_cover.png?fit=1024%2C1024&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1611,"url":"https:\/\/macromillcnc.com\/2026\/11\/08\/fanuc-cnc-simulators-built-in-cycles\/","url_meta":{"origin":1880,"position":4},"title":"FANUC CNC Simulators With Built-In Cycles: What MacroMill&#8217;s Simulators Solve","author":"MacroMill","date":"November 8, 2026","format":false,"excerpt":"Learn CNC without machine time, prove macros before cutting and generate code for threads, grooves, pockets and patterns. See the built-in cycles in MacroMill's FANUC-style lathe and VMC simulators.","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/macromillcnc.com\/category\/tutorials\/"},"img":{"alt_text":"MacroMill FANUC CNC simulator all-in-one bundle","src":"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-simulator-all-in-one-bundle.png?fit=1080%2C1080&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-simulator-all-in-one-bundle.png?fit=1080%2C1080&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-simulator-all-in-one-bundle.png?fit=1080%2C1080&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-simulator-all-in-one-bundle.png?fit=1080%2C1080&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/macromill-fanuc-simulator-all-in-one-bundle.png?fit=1080%2C1080&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1675,"url":"https:\/\/macromillcnc.com\/2026\/11\/10\/fanuc-macro-while-loop\/","url_meta":{"origin":1880,"position":5},"title":"How a FANUC Macro WHILE Loop Works \u2014 Tip of the Iceberg","author":"MacroMill","date":"November 10, 2026","format":false,"excerpt":"Learn how a FANUC macro WHILE loop works: WHILE[...]DO1, the 0\/90\/180\/270 keyway walkthrough, and how MacroMill helps you master Macro B.","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/macromillcnc.com\/category\/tutorials\/"},"img":{"alt_text":"Step-through table in the MacroMill simulator showing a FANUC macro WHILE loop: counters 0 to 3 are true at 0, 90, 180 and 270 degrees, counter 4 is false and exits","src":"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/fanuc-macro-while-loop-step-through.jpg?fit=1200%2C675&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/fanuc-macro-while-loop-step-through.jpg?fit=1200%2C675&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/fanuc-macro-while-loop-step-through.jpg?fit=1200%2C675&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/fanuc-macro-while-loop-step-through.jpg?fit=1200%2C675&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/11\/fanuc-macro-while-loop-step-through.jpg?fit=1200%2C675&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/macromillcnc.com\/wp-content\/uploads\/2026\/12\/while-if-fanuc-macro-depth-loop.jpg?fit=1920%2C1080&ssl=1","_links":{"self":[{"href":"https:\/\/macromillcnc.com\/wp-json\/wp\/v2\/posts\/1880","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/macromillcnc.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/macromillcnc.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/macromillcnc.com\/wp-json\/wp\/v2\/users\/279632934"}],"replies":[{"embeddable":true,"href":"https:\/\/macromillcnc.com\/wp-json\/wp\/v2\/comments?post=1880"}],"version-history":[{"count":0,"href":"https:\/\/macromillcnc.com\/wp-json\/wp\/v2\/posts\/1880\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/macromillcnc.com\/wp-json\/wp\/v2\/media\/1878"}],"wp:attachment":[{"href":"https:\/\/macromillcnc.com\/wp-json\/wp\/v2\/media?parent=1880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/macromillcnc.com\/wp-json\/wp\/v2\/categories?post=1880"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/macromillcnc.com\/wp-json\/wp\/v2\/tags?post=1880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}