# Recreating the while block

**URL:** <https://forum.makecode.com/t/recreating-the-while-block/10134>\
**Category:** micro:bit\
**Created:** [September 20, 2021, 3:55pm UTC](https://forum.makecode.com/t/recreating-the-while-block/10134 "2021-09-20T15:55:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elay7771](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/elay7771/32/4977_2.png) [@Elay7771](https://forum.makecode.com/u/Elay7771)\
**Post date:** [September 20, 2021, 3:55pm UTC](https://forum.makecode.com/t/recreating-the-while-block/10134/1 "2021-09-20T15:55:25Z")

</div>

(reposting to the microbit community)  
Is there a way I can make my own while block?  
I want my extension to have a while  
Block that behaves exactly like the default while block in loops. If there is a way to take the already existing while block and change its name and shadow that also would be great.  
Example:  
 ![Screenshot 2021-09-18 220922](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/1/166b765df52e3417bcc133f38026009fe4bb7ada.png)

---

<div class="post-metadata">

**Author:** ![bsiever](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bsiever/32/1032_2.png) [@bsiever](https://forum.makecode.com/u/bsiever)\
**Post date:** [September 21, 2021, 4:43am UTC](https://forum.makecode.com/t/recreating-the-while-block/10134/2 "2021-09-21T04:43:51Z")

</div>

You might take a look at this post: [Creating an multi handler function in an extension - #2 by E-EnerG-Gamecentral](https://forum.makecode.com/t/creating-an-multi-handler-function-in-an-extension/10041/2)

Here’s my answer from there, which might actually fit:

> This may not solve your problems, but the MakeCode playground is a great tool to explore the block styles and prototype blocks. See: [https://makecode.com/playground](https://makecode.com/playground) .
> 
> About the closest example is has is the in-line [event handler](https://makecode.com/playground#events).

You may want to follow the link and:

1. Switch to the micro:bit view (The “Editor” drop down menu)
2. Pick “Events” in the Sample menu
3. Click `Run`
4. Select the Puzzle Piece palette to see what the examples look like. The “`on an inline event`” looks like a pretty good fit. It can be modified to have a parameter.

That being said, I’m not sure how easy/hard it is to get the behavior you want. I suspect it isn’t too bad.

Bill

---

<div class="post-metadata">

**Author:** ![Elay7771](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/elay7771/32/4977_2.png) [@Elay7771](https://forum.makecode.com/u/Elay7771)\
**Post date:** [September 22, 2021, 4:28pm UTC](https://forum.makecode.com/t/recreating-the-while-block/10134/3 "2021-09-22T16:28:13Z")

</div>

Hi, thank you very much for the reply.  
Unfortunately the problem is **not making the block itself** , but rather the problem is if I make the block, it takes boolean as a parameter and I \*\*can’t recheck the condition (the condition returns the at first it will always be true). Is there a way to fix this?

---

<div class="post-metadata">

**Author:** ![bsiever](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bsiever/32/1032_2.png) [@bsiever](https://forum.makecode.com/u/bsiever)\
**Post date:** [September 24, 2021, 4:02pm UTC](https://forum.makecode.com/t/recreating-the-while-block/10134/4 "2021-09-24T16:02:15Z")

</div>

Sorry. I didn’t really think about an expression vs. a value.

This may be something to ask about via the issues on the pxt github. If there’s no way to do this now, I suspect they _could_ support new syntax for these blocks that would convert expressions to lambdas. For example, a normal **value-based** block may have parameters like:

```auto
   export function onEventAsStatement(value: boolean, handler: () => void) {
        if(value) {
            handler();
        }
    }

```

And one that accepts a lambda expressions may look like:

```auto
   export function onEventAsStatement(value: boolean=>boolean, handler: () => void) {
        while(value) {
            handler();
        }
    }

```

The expressions created in blocks would either be converted to a value or a lambda based on the parameter type. Parameters of the style `TYPE=>TYPE` would be treated as a lambda with the `TYPE` as the expected expression type. Any `()=>void` expressions would be code blocks (maybe support multiple code blocks too for if-else style behavior). Of course, there may be a bunch of problems with this approach that I’m not considering…

Bill
