# Blocks for breaking and continuing

**URL:** <https://forum.makecode.com/t/blocks-for-breaking-and-continuing/5316>\
**Category:** PXT\
**Created:** [January 3, 2021, 1:52am UTC](https://forum.makecode.com/t/blocks-for-breaking-and-continuing/5316 "2021-01-03T01:52:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [January 3, 2021, 1:52am UTC](https://forum.makecode.com/t/blocks-for-breaking-and-continuing/5316/1 "2021-01-03T01:52:09Z")

</div>

As the title says, a block for the statements `break` and `continue`, that would go under `Loops` and be a light green block like the `while` and `for` blocks?

---

<div class="post-metadata">

**Author:** ![joshkeys19](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/joshkeys19/32/2182_2.png) [@joshkeys19](https://forum.makecode.com/u/joshkeys19)\
**Post date:** [January 21, 2021, 4:41pm UTC](https://forum.makecode.com/t/blocks-for-breaking-and-continuing/5316/2 "2021-01-21T16:41:08Z")

</div>

Hi UnsignedArduino,

I’m not sure if this is what you are looking for, but here is a non elegant way I was able to achieve this. I created a custom.ts file for this example for you:

`
/**
 * Custom blocks
 */
//% weight=100 color=#0fbc11 icon=""
namespace customLoops {
    let breakVar = false
```
/**
 * TODO: describe your function here
 */
//% block="While $condition"
export function WhileLoop(condition:boolean,code: () => void):void
 {

```
while(true)
{
if(condition && !breakVar) //If a break hasn’t occured and condition still == true
{
code() //Run the user provided code
}
```
 basic.pause(200) //Pause for 200 ms to allow the scheduler to run

```
}
```
}

//% block="Break"
export function BreakFunction(): void {
    breakVar = true //Set the breakVar variable to true to create a break
    
}

/**
 * TODO: describe your function here
 */
//% block="Continue"
export function ContinueFunction() {
    breakVar = false //Set the breakVar variable to false to allow loop to run again
}

```
`

`}
`

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/3/3c9877adf367a532a136047caee3c65b413e2974.png)

Hope this helps.

Thanks,  
Josh

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [January 21, 2021, 5:28pm UTC](https://forum.makecode.com/t/blocks-for-breaking-and-continuing/5316/3 "2021-01-21T17:28:35Z")

</div>

Thanks, but there is already commands to do this in TS, so I want blocks for those commands. I already do this in blocks anyway. (have a `break` variable)

Side note: You should surround code with 3 backticks and a newline like this:

```  
code here  
```

would look like this:

```auto
code here

```

---

<div class="post-metadata">

**Author:** ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)\
**Post date:** [January 21, 2021, 6:59pm UTC](https://forum.makecode.com/t/blocks-for-breaking-and-continuing/5316/4 "2021-01-21T18:59:22Z")

</div>

We do actually support these blocks, but they’re enabled on a per editor basis as they’re considered advanced / can be confusing for new coders - e.g. the ev3 editor has them:

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/a/aaf38f9e9ec454f7e7b6bbf64fe616caefe53be1.png)

They’re toggled with [target flags](https://github.com/microsoft/pxt/blob/b15f6789523f775e7f90abcdf9d9153b216a5ffb/localtypings/pxtarget.d.ts#L140-L141).

If you want to see these in a particular editor a feature request in that repo would be helpful to track!

---

<div class="post-metadata">

**Author:** ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)\
**Post date:** [January 21, 2021, 7:11pm UTC](https://forum.makecode.com/t/blocks-for-breaking-and-continuing/5316/5 "2021-01-21T19:11:41Z")

</div>

Done.

> <https://github.com/microsoft/pxt-arcade/issues/2946>
>
> Originally posted here: https://forum.makecode.com/t/blocks-for-breaking-and-continuing/5316/4
> As the title says, a block for the statements break and continue, that would go under Loops and...

---

<div class="post-metadata">

**Author:** ![GameGod](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/gamegod/32/2756_2.png) [@GameGod](https://forum.makecode.com/u/GameGod)\
**Post date:** [January 24, 2021, 1:33am UTC](https://forum.makecode.com/t/blocks-for-breaking-and-continuing/5316/6 "2021-01-24T01:33:32Z")

</div>

Wow, they added it!

---

<div class="post-metadata">

**Author:** ![joshkeys19](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/joshkeys19/32/2182_2.png) [@joshkeys19](https://forum.makecode.com/u/joshkeys19)\
**Post date:** [March 10, 2021, 4:11pm UTC](https://forum.makecode.com/t/blocks-for-breaking-and-continuing/5316/7 "2021-03-10T16:11:12Z")

</div>

Thanks for the tip! Sorry, I just realized I never replied. I had been using an HTML code tag

---

<div class="post-metadata">

**Author:** ![THEb0nny](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/theb0nny/32/3500_2.png) [@THEb0nny](https://forum.makecode.com/u/THEb0nny)\
**Post date:** [November 29, 2021, 5:00pm UTC](https://forum.makecode.com/t/blocks-for-breaking-and-continuing/5316/8 "2021-11-29T17:00:22Z")

</div>

In the beta version of ev3, these blocks are missing in the visual editor. If you write them in js and translate them into blocks, they will be displayed. Can you change and render in beta? They are displayed in the stable version.
