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?
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
}
}
Hope this helps.
Thanks,
Josh
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:
code here
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:
They’re toggled with target flags.
If you want to see these in a particular editor a feature request in that repo would be helpful to track!
Done.
Wow, they added it!
Thanks for the tip! Sorry, I just realized I never replied. I had been using an HTML code tag
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.