Break and Continue Blocks + Naming Control Flow Statements

A feature I’d like to see in Hopscotch is:

A ‘break’ block.
This block breaks and ends the current control flow statement you are in. (the lowest one)

A ‘continue’ block specifically for loops. It immediately ends the current index of the loop, and goes to the next one.

Also - being able to name Control Flpw statements. Then you can break or continue a specific one like this:

thisHere: if true {
    // this line runs
    if true {
         break thisHere
         // this line wont run
    }
    // this line won’t run
}
// immediately hops down here

This could also be a great first step for ‘returning’ from methods.

I’d use it for this type of project:

Any project with huge nested if-while-repeat statements. So you can exit out of them quiccly

I’ve seen something similar in another programming languages, it looks like this:

Swift has it.

foo: while true {}


Perfect for

  • if statements
  • while loops
  • repeat blocks
  • (for-in loops please)
  • (switch statements pretty please)
12 Likes

We really need this. It would be so awesome if we did. First Post

4 Likes

Pretty cool idea

2 Likes

Coolios.

2 Likes

I think it will be harder for the devs to implement this. Especially since ‘break’ would have to ‘automatically’ end the repeat block even if it hasn’t finished. Either way, it would be perfect addition, and it would also make the code more efficient. It would be very useful for objects with moving animations like ‘move forward [300]’, which if tapped would originally need to wait for the loop to end before resetting its own animation.

4 Likes

That’s why there would be “check once if else” inside repeat forever blocks.

Example:

Repeat Forever:
Check once if: -1 = Supreme
Set Text: “Petrichor is Supreme”
else:
break
…and then whatever would be after.

2 Likes

Also, I think there should be an option to ‘broadcast’ named statements. Because most programming language uses ‘void’ (text) or ‘when broadcasted’ (blocks).

2 Likes

The beta editor has a broadcast block. I don’t know if it does exactly what you’re saying one should do, though.

2 Likes

The kind that’s used in real programming, except it has ‘void’ next to a function and it is basically a set of code that doesn’t run until it gets called. The broadcast feature in the beta is probably for the chat bot.

2 Likes

I don’t have the beta, so I have no idea if it is or not.

2 Likes

We do have ‘when ()=()’ which somewhat does the same thing, your example just makes it even easier to code.

2 Likes

Types would be nice
Then we can make strutcts

I think there are 100+ blocks the devs could add to Hopscotch including your ‘break’ and ‘continue’ blocks, and if there was that many more blocks, there should be better organization, as well as a ‘search blocks’ feature.

1 Like

However, we must remember that this is a kids’ coding app, and as such there cannot be too many blocks, as remembering how all of them function would be difficult for a lot of 8-12 year olds.

1 Like

Oyes that is true
What if there was a “beginners set” and a “complete set”

And maybe a “favorites” to save your favorites

1 Like

Oh please do add this THT. It would be super helpful for stopping repeat forever loops and checking if music is paused.

3 Likes

Oh yeah, it would be really useful for music. I didn’t think about that.

2 Likes

oh yeah
I forgot about they have repeat forever loops

With “break” we could turn this repeat forever into a “while” loop or “repeat until” block.

2 Likes

yess

1 Like

Yes! Absolutely! I would love to see this.

1 Like