---
title: Using WHILE and IF in Macro B
description: Making a program that will face ANY size block using Macro B. This was taken from one of our YouTube Live Streams.
image: https://blog.caminstructor.com/hubfs/Macro%20Stream%20Thumb%206.jpg
---

[CamInstructor ![CamInstructor Inc.](https://blog.caminstructor.com/hs-fs/hubfs/camInstructor_Inc_March2018/images/logo%20(1).png?width=190&name=logo%20(1).png) ![CamInstructor Inc.](https://blog.caminstructor.com/hs-fs/hubfs/camInstructor_Inc_March2018/images/logo-white%20(1).png?width=190&name=logo-white%20(1).png)](https://caminstructor.com/)

- [Home](https://caminstructor.com/)
- [Online Courses](https://caminstructor.com/mastercam-courses)
- [Video Blog](https://blog.caminstructor.com/)
- [Teachers](https://caminstructor.com/mastercam-academic)
- Resources 
    - [Learn Mastercam](https://info.caminstructor.com/learn-mastercam)
    - [Teach Mastercam](https://info.caminstructor.com/teach-mastercam)
    - [Mastercam Certification](https://info.caminstructor.com/caminstructor-certification)
    - [Free Lessons](https://info.caminstructor.com/caminstructor-resource-hub)
    - [CEU Training](https://caminstructor.com/ceu-training)
    - [Sign Up](https://caminstructor.com/sign-up)
    - [Certification](https://caminstructor.com/certification)
- [Login](https://caminstructor.com/login)

# [camInstructor Video Blog](https://blog.caminstructor.com)

## [Using WHILE and IF in Macro B](https://blog.caminstructor.com/using-while-and-if-in-macro-b)

 6/1/20 8:00 AM / by [camInstructor Mike](https://blog.caminstructor.com/author/caminstructor-mike)

- [Tweet](https://twitter.com/share)

Making a program that will face ANY size block using Macro B. This was taken from one of our YouTube Live Streams.

---

This video is pulled from our last live stream. The full stream was roughly an hour long. <https://go.aws/3edlvYK>

Stream starts at about 5:11

Basic g code is just a way to 'connect the dots'. Custom Macro B allows the programmer to put some logic into the g code with tools such as loops and branches. It also provides additional Math functions and the ability to access information from the machine. Custom Macro B programs can be simple, they can be complex. From custom canned drilling cycles to probing routines to cutting simple shapes, there's almost nothing you can't do with Macro B programming.

0:00 Stream waiting to start

5:11 Introduction

6:27 Overview of softwares used in the demo

8:08 Starting the program

19:04 Add parameters to the program

26:13 Discussing the need for logic in this program

28:44 Creating the logic discussed

39:05 First look at NCPlots live variable display

41:00 THE BIG ANNOUNCEMENT

45:00 Back to the program

46:00 Into the While loop

50:46 Looking at an If statement

1:04:30 Testing on multiple blocks

1:08:30 Wrapping it up

 

Be sure to watch videos 1 and 2 in our ever evolving macro series... 

[Macro B - 1](https://blog.caminstructor.com/macro-b-programming)

[Macro B - 2](https://blog.caminstructor.com/caminstructor-tips-macro-b-programming-part-2)

---

**Want to learn more about Mastercam? Check out;**

**camInstructor for [Teachers](https://info.caminstructor.com/teach-mastercam) - [Independent Learners](https://info.caminstructor.com/learn-mastercam) - [Students](https://info.caminstructor.com/learn-mastercam)**

---

 

 

 Topics: [CNC](https://blog.caminstructor.com/topic/cnc), [Macro](https://blog.caminstructor.com/topic/macro), [Mill](https://blog.caminstructor.com/topic/mill), [gcode](https://blog.caminstructor.com/topic/gcode), [live stream](https://blog.caminstructor.com/topic/live-stream)

![camInstructor Mike](https://blog.caminstructor.com/hs-fs/hubfs/20180517_144905-155786-edited-341229-edited.jpg?width=100&height=100&name=20180517_144905-155786-edited-341229-edited.jpg)

#### Written by [camInstructor Mike](https://blog.caminstructor.com/author/caminstructor-mike)

camInstructor Mike is Mike Wearne, an avid machinist, cnc programmer and overall connoisseur of all things machining. Mike is one of camInstructor's resident cad/cam/cnc experts and works part time at his local college teaching aspiring machinists how to program CNC Machines of all types.

### Subscribe to Email Updates

By subscribing, you consent to receive marketing emails, newsletters, updates, and promotional communications from CamInstructor. You may withdraw your consent and unsubscribe at any time using the unsubscribe link included in our emails. Your information will be handled in accordance with our Privacy Policy.

[![New call-to-action](https://no-cache.hubspot.com/cta/default/3917006/547a6ca2-8624-4d05-b2d2-6a441cd2e43b.png)](https://cta-redirect.hubspot.com/cta/redirect/3917006/547a6ca2-8624-4d05-b2d2-6a441cd2e43b)

- Recent
- Popular
- Categories

### Lists by Topic

- [Mastercam (82)](https://blog.caminstructor.com/tag/mastercam)
- [Mastercam 2019 (19)](https://blog.caminstructor.com/tag/mastercam-2019)
- [Mastercam Dynamic Milling (18)](https://blog.caminstructor.com/tag/mastercam-dynamic-milling)
- [Mastercam Tips (15)](https://blog.caminstructor.com/tag/mastercam-tips)
- [Mill (15)](https://blog.caminstructor.com/tag/mill)
- [CNC (13)](https://blog.caminstructor.com/tag/cnc)
- [5 Axis (10)](https://blog.caminstructor.com/tag/5-axis)
- [2022 (8)](https://blog.caminstructor.com/tag/2022)
- [Mastercam 2020 (8)](https://blog.caminstructor.com/tag/mastercam-2020)
- [Mastercam Linking Parameters (6)](https://blog.caminstructor.com/tag/mastercam-linking-parameters)
- [2024 (5)](https://blog.caminstructor.com/tag/2024)
- [Haas (5)](https://blog.caminstructor.com/tag/haas)
- [Xometry (5)](https://blog.caminstructor.com/tag/xometry)
- [gcode (5)](https://blog.caminstructor.com/tag/gcode)
- [HLE (4)](https://blog.caminstructor.com/tag/hle)
- [Lathe (4)](https://blog.caminstructor.com/tag/lathe)
- [Mastercam 2023 (4)](https://blog.caminstructor.com/tag/mastercam-2023)
- [Setup Operate (4)](https://blog.caminstructor.com/tag/setup-operate)
- [Solids (4)](https://blog.caminstructor.com/tag/solids)
- [Wireframe (4)](https://blog.caminstructor.com/tag/wireframe)
- [live stream (4)](https://blog.caminstructor.com/tag/live-stream)
- [Macro (3)](https://blog.caminstructor.com/tag/macro)
- [Shortcut (3)](https://blog.caminstructor.com/tag/shortcut)
- [tesla (3)](https://blog.caminstructor.com/tag/tesla)
- [3D Printing (2)](https://blog.caminstructor.com/tag/3d-printing)
- [Benchmark (2)](https://blog.caminstructor.com/tag/benchmark)
- [Help (2)](https://blog.caminstructor.com/tag/help)
- [Interview (2)](https://blog.caminstructor.com/tag/interview)
- [Machine Group Setup (2)](https://blog.caminstructor.com/tag/machine-group-setup)
- [Machinist (2)](https://blog.caminstructor.com/tag/machinist)
- [Parallel (2)](https://blog.caminstructor.com/tag/parallel)
- [Stock (2)](https://blog.caminstructor.com/tag/stock)
- [Swarf (2)](https://blog.caminstructor.com/tag/swarf)
- [Tips (2)](https://blog.caminstructor.com/tag/tips)
- [cybertruck (2)](https://blog.caminstructor.com/tag/cybertruck)
- [editors (2)](https://blog.caminstructor.com/tag/editors)
- [engrave (2)](https://blog.caminstructor.com/tag/engrave)
- [millturn (2)](https://blog.caminstructor.com/tag/millturn)
- [minimum requirements (2)](https://blog.caminstructor.com/tag/minimum-requirements)
- [postprocessor (2)](https://blog.caminstructor.com/tag/postprocessor)
- [3D (1)](https://blog.caminstructor.com/tag/3d)
- [5 Axis Curve (1)](https://blog.caminstructor.com/tag/5-axis-curve)
- [Align to Face (1)](https://blog.caminstructor.com/tag/align-to-face)
- [Beta (1)](https://blog.caminstructor.com/tag/beta)
- [Big Event (1)](https://blog.caminstructor.com/tag/big-event)
- [CannedCycles (1)](https://blog.caminstructor.com/tag/cannedcycles)
- [Certification (1)](https://blog.caminstructor.com/tag/certification)
- [Chaining (1)](https://blog.caminstructor.com/tag/chaining)
- [Entry Motion (1)](https://blog.caminstructor.com/tag/entry-motion)
- [Excel (1)](https://blog.caminstructor.com/tag/excel)
- [Flow (1)](https://blog.caminstructor.com/tag/flow)
- [Helix Bore (1)](https://blog.caminstructor.com/tag/helix-bore)
- [Hiring (1)](https://blog.caminstructor.com/tag/hiring)
- [Impeller (1)](https://blog.caminstructor.com/tag/impeller)
- [Keyboard Shortcuts (1)](https://blog.caminstructor.com/tag/keyboard-shortcuts)
- [MFGDay (1)](https://blog.caminstructor.com/tag/mfgday)
- [Mastercam 2021 (1)](https://blog.caminstructor.com/tag/mastercam-2021)
- [Mastercam 2024 (1)](https://blog.caminstructor.com/tag/mastercam-2024)
- [Mastercam X3 (1)](https://blog.caminstructor.com/tag/mastercam-x3)
- [Mastercam X9 (1)](https://blog.caminstructor.com/tag/mastercam-x9)
- [ModuleWorks (1)](https://blog.caminstructor.com/tag/moduleworks)
- [Morph (1)](https://blog.caminstructor.com/tag/morph)
- [MultiAxisRoughing (1)](https://blog.caminstructor.com/tag/multiaxisroughing)
- [On Screen Controls (1)](https://blog.caminstructor.com/tag/on-screen-controls)
- [OptiRough (1)](https://blog.caminstructor.com/tag/optirough)
- [Oscillate (1)](https://blog.caminstructor.com/tag/oscillate)
- [Planes (1)](https://blog.caminstructor.com/tag/planes)
- [Pocket (1)](https://blog.caminstructor.com/tag/pocket)
- [Podcast (1)](https://blog.caminstructor.com/tag/podcast)
- [Quick Reference Card (1)](https://blog.caminstructor.com/tag/quick-reference-card)
- [QuickMask (1)](https://blog.caminstructor.com/tag/quickmask)
- [Rubix Cube (1)](https://blog.caminstructor.com/tag/rubix-cube)
- [SelectionBar (1)](https://blog.caminstructor.com/tag/selectionbar)
- [Siri (1)](https://blog.caminstructor.com/tag/siri)
- [SolidWorks (1)](https://blog.caminstructor.com/tag/solidworks)
- [Stock Model (1)](https://blog.caminstructor.com/tag/stock-model)
- [Stream Deck (1)](https://blog.caminstructor.com/tag/stream-deck)
- [Tabs (1)](https://blog.caminstructor.com/tag/tabs)
- [Tools (1)](https://blog.caminstructor.com/tag/tools)
- [Tradeshow (1)](https://blog.caminstructor.com/tag/tradeshow)
- [Triangular Mesh (1)](https://blog.caminstructor.com/tag/triangular-mesh)
- [UMC (1)](https://blog.caminstructor.com/tag/umc)
- [VR (1)](https://blog.caminstructor.com/tag/vr)
- [Vericut (1)](https://blog.caminstructor.com/tag/vericut)
- [Virtual Reality (1)](https://blog.caminstructor.com/tag/virtual-reality)
- [Windows11 (1)](https://blog.caminstructor.com/tag/windows11)
- [Wordle (1)](https://blog.caminstructor.com/tag/wordle)
- [ai (1)](https://blog.caminstructor.com/tag/ai)
- [boolean (1)](https://blog.caminstructor.com/tag/boolean)
- [dark mode (1)](https://blog.caminstructor.com/tag/dark-mode)
- [deboss (1)](https://blog.caminstructor.com/tag/deboss)
- [drill (1)](https://blog.caminstructor.com/tag/drill)
- [emboss (1)](https://blog.caminstructor.com/tag/emboss)
- [feedrate (1)](https://blog.caminstructor.com/tag/feedrate)
- [games (1)](https://blog.caminstructor.com/tag/games)
- [job (1)](https://blog.caminstructor.com/tag/job)
- [levels (1)](https://blog.caminstructor.com/tag/levels)
- [machine simulation (1)](https://blog.caminstructor.com/tag/machine-simulation)
- [news (1)](https://blog.caminstructor.com/tag/news)
- [online (1)](https://blog.caminstructor.com/tag/online)
- [phone (1)](https://blog.caminstructor.com/tag/phone)
- [pocketNC (1)](https://blog.caminstructor.com/tag/pocketnc)
- [quick tips (1)](https://blog.caminstructor.com/tag/quick-tips)
- [simulation (1)](https://blog.caminstructor.com/tag/simulation)
- [softjaws (1)](https://blog.caminstructor.com/tag/softjaws)
- [vise (1)](https://blog.caminstructor.com/tag/vise)

see all

Search Blog

### Posts by Topic

- [Mastercam (82)](https://blog.caminstructor.com/tag/mastercam)
- [Mastercam 2019 (19)](https://blog.caminstructor.com/tag/mastercam-2019)
- [Mastercam Dynamic Milling (18)](https://blog.caminstructor.com/tag/mastercam-dynamic-milling)
- [Mastercam Tips (15)](https://blog.caminstructor.com/tag/mastercam-tips)
- [Mill (15)](https://blog.caminstructor.com/tag/mill)
- [CNC (13)](https://blog.caminstructor.com/tag/cnc)
- [5 Axis (10)](https://blog.caminstructor.com/tag/5-axis)
- [2022 (8)](https://blog.caminstructor.com/tag/2022)
- [Mastercam 2020 (8)](https://blog.caminstructor.com/tag/mastercam-2020)
- [Mastercam Linking Parameters (6)](https://blog.caminstructor.com/tag/mastercam-linking-parameters)
- [2024 (5)](https://blog.caminstructor.com/tag/2024)
- [Haas (5)](https://blog.caminstructor.com/tag/haas)
- [Xometry (5)](https://blog.caminstructor.com/tag/xometry)
- [gcode (5)](https://blog.caminstructor.com/tag/gcode)
- [HLE (4)](https://blog.caminstructor.com/tag/hle)
- [Lathe (4)](https://blog.caminstructor.com/tag/lathe)
- [Mastercam 2023 (4)](https://blog.caminstructor.com/tag/mastercam-2023)
- [Setup Operate (4)](https://blog.caminstructor.com/tag/setup-operate)
- [Solids (4)](https://blog.caminstructor.com/tag/solids)
- [Wireframe (4)](https://blog.caminstructor.com/tag/wireframe)
- [live stream (4)](https://blog.caminstructor.com/tag/live-stream)
- [Macro (3)](https://blog.caminstructor.com/tag/macro)
- [Shortcut (3)](https://blog.caminstructor.com/tag/shortcut)
- [tesla (3)](https://blog.caminstructor.com/tag/tesla)
- [3D Printing (2)](https://blog.caminstructor.com/tag/3d-printing)
- [Benchmark (2)](https://blog.caminstructor.com/tag/benchmark)
- [Help (2)](https://blog.caminstructor.com/tag/help)
- [Interview (2)](https://blog.caminstructor.com/tag/interview)
- [Machine Group Setup (2)](https://blog.caminstructor.com/tag/machine-group-setup)
- [Machinist (2)](https://blog.caminstructor.com/tag/machinist)
- [Parallel (2)](https://blog.caminstructor.com/tag/parallel)
- [Stock (2)](https://blog.caminstructor.com/tag/stock)
- [Swarf (2)](https://blog.caminstructor.com/tag/swarf)
- [Tips (2)](https://blog.caminstructor.com/tag/tips)
- [cybertruck (2)](https://blog.caminstructor.com/tag/cybertruck)
- [editors (2)](https://blog.caminstructor.com/tag/editors)
- [engrave (2)](https://blog.caminstructor.com/tag/engrave)
- [millturn (2)](https://blog.caminstructor.com/tag/millturn)
- [minimum requirements (2)](https://blog.caminstructor.com/tag/minimum-requirements)
- [postprocessor (2)](https://blog.caminstructor.com/tag/postprocessor)
- [3D (1)](https://blog.caminstructor.com/tag/3d)
- [5 Axis Curve (1)](https://blog.caminstructor.com/tag/5-axis-curve)
- [Align to Face (1)](https://blog.caminstructor.com/tag/align-to-face)
- [Beta (1)](https://blog.caminstructor.com/tag/beta)
- [Big Event (1)](https://blog.caminstructor.com/tag/big-event)
- [CannedCycles (1)](https://blog.caminstructor.com/tag/cannedcycles)
- [Certification (1)](https://blog.caminstructor.com/tag/certification)
- [Chaining (1)](https://blog.caminstructor.com/tag/chaining)
- [Entry Motion (1)](https://blog.caminstructor.com/tag/entry-motion)
- [Excel (1)](https://blog.caminstructor.com/tag/excel)
- [Flow (1)](https://blog.caminstructor.com/tag/flow)
- [Helix Bore (1)](https://blog.caminstructor.com/tag/helix-bore)
- [Hiring (1)](https://blog.caminstructor.com/tag/hiring)
- [Impeller (1)](https://blog.caminstructor.com/tag/impeller)
- [Keyboard Shortcuts (1)](https://blog.caminstructor.com/tag/keyboard-shortcuts)
- [MFGDay (1)](https://blog.caminstructor.com/tag/mfgday)
- [Mastercam 2021 (1)](https://blog.caminstructor.com/tag/mastercam-2021)
- [Mastercam 2024 (1)](https://blog.caminstructor.com/tag/mastercam-2024)
- [Mastercam X3 (1)](https://blog.caminstructor.com/tag/mastercam-x3)
- [Mastercam X9 (1)](https://blog.caminstructor.com/tag/mastercam-x9)
- [ModuleWorks (1)](https://blog.caminstructor.com/tag/moduleworks)
- [Morph (1)](https://blog.caminstructor.com/tag/morph)
- [MultiAxisRoughing (1)](https://blog.caminstructor.com/tag/multiaxisroughing)
- [On Screen Controls (1)](https://blog.caminstructor.com/tag/on-screen-controls)
- [OptiRough (1)](https://blog.caminstructor.com/tag/optirough)
- [Oscillate (1)](https://blog.caminstructor.com/tag/oscillate)
- [Planes (1)](https://blog.caminstructor.com/tag/planes)
- [Pocket (1)](https://blog.caminstructor.com/tag/pocket)
- [Podcast (1)](https://blog.caminstructor.com/tag/podcast)
- [Quick Reference Card (1)](https://blog.caminstructor.com/tag/quick-reference-card)
- [QuickMask (1)](https://blog.caminstructor.com/tag/quickmask)
- [Rubix Cube (1)](https://blog.caminstructor.com/tag/rubix-cube)
- [SelectionBar (1)](https://blog.caminstructor.com/tag/selectionbar)
- [Siri (1)](https://blog.caminstructor.com/tag/siri)
- [SolidWorks (1)](https://blog.caminstructor.com/tag/solidworks)
- [Stock Model (1)](https://blog.caminstructor.com/tag/stock-model)
- [Stream Deck (1)](https://blog.caminstructor.com/tag/stream-deck)
- [Tabs (1)](https://blog.caminstructor.com/tag/tabs)
- [Tools (1)](https://blog.caminstructor.com/tag/tools)
- [Tradeshow (1)](https://blog.caminstructor.com/tag/tradeshow)
- [Triangular Mesh (1)](https://blog.caminstructor.com/tag/triangular-mesh)
- [UMC (1)](https://blog.caminstructor.com/tag/umc)
- [VR (1)](https://blog.caminstructor.com/tag/vr)
- [Vericut (1)](https://blog.caminstructor.com/tag/vericut)
- [Virtual Reality (1)](https://blog.caminstructor.com/tag/virtual-reality)
- [Windows11 (1)](https://blog.caminstructor.com/tag/windows11)
- [Wordle (1)](https://blog.caminstructor.com/tag/wordle)
- [ai (1)](https://blog.caminstructor.com/tag/ai)
- [boolean (1)](https://blog.caminstructor.com/tag/boolean)
- [dark mode (1)](https://blog.caminstructor.com/tag/dark-mode)
- [deboss (1)](https://blog.caminstructor.com/tag/deboss)
- [drill (1)](https://blog.caminstructor.com/tag/drill)
- [emboss (1)](https://blog.caminstructor.com/tag/emboss)
- [feedrate (1)](https://blog.caminstructor.com/tag/feedrate)
- [games (1)](https://blog.caminstructor.com/tag/games)
- [job (1)](https://blog.caminstructor.com/tag/job)
- [levels (1)](https://blog.caminstructor.com/tag/levels)
- [machine simulation (1)](https://blog.caminstructor.com/tag/machine-simulation)
- [news (1)](https://blog.caminstructor.com/tag/news)
- [online (1)](https://blog.caminstructor.com/tag/online)
- [phone (1)](https://blog.caminstructor.com/tag/phone)
- [pocketNC (1)](https://blog.caminstructor.com/tag/pocketnc)
- [quick tips (1)](https://blog.caminstructor.com/tag/quick-tips)
- [simulation (1)](https://blog.caminstructor.com/tag/simulation)
- [softjaws (1)](https://blog.caminstructor.com/tag/softjaws)
- [vise (1)](https://blog.caminstructor.com/tag/vise)

See all

### Recent Posts

![ We support different card for pay](https://blog.caminstructor.com/hs-fs/hubfs/camInstructor_Inc_March2018/images/card-logos.png?width=208&name=card-logos.png)

![Site secured by Rapid SSL](https://blog.caminstructor.com/hs-fs/hubfs/camInstructor_Inc_March2018/images/rapid-logo.png?width=90&name=rapid-logo.png)

- Resources 
    - [Blog](https://blog.caminstructor.com/)
    - [Learn Mastercam](https://info.caminstructor.com/learn-mastercam)
    - [Teach Mastercam](https://info.caminstructor.com/teach-mastercam)
- About 
    - [About camInstructor](https://caminstructor.com/about-caminstructor)
    - [FAQ](https://caminstructor.com/faq)
    - [Contact Us](https://caminstructor.com/contact)
    - [Jobs](https://caminstructor.com/jobs)
    - [Privacy Statement](https://caminstructor.com/index.php?p=6)
- Store 
    - [Online Courses](https://caminstructor.com/mastercam-courses)
    - [Single Courses](https://caminstructor.com/single-courses)
    - [Text Books](https://caminstructor.com/mastercam-textbooks)
    - [Software](https://caminstructor.com/NCPlot-Discriminator)
    - [Shipping](https://caminstructor.com/shipping)
    - [Satisfaction Guaranteed](https://caminstructor.com/guarantee)
    - [Terms & Conditions](https://caminstructor.com/index.php?p=7)
- Customers 
    - [Login](https://caminstructor.com/login)

[![Click to scroll top](https://blog.caminstructor.com/hs-fs/hubfs/camInstructor_Inc_March2018/images/scroll-top@2x.png?width=25&name=scroll-top@2x.png)](https://blog.caminstructor.com/using-while-and-if-in-macro-b#top)

![We are Mastercamp Partner](https://blog.caminstructor.com/hubfs/camInstructor_Inc_March2018/images/master-partner-logos.png)

© 2009 - 2020. CamInstructor Inc.