radon-project / radon

The Radon Programming Language
https://radon-project.github.io
GNU General Public License v3.0
23 stars 2 forks source link

`Switch...Case...Default` syntax addition proposal. (REP-5) #85

Closed Almas-Ali closed 2 months ago

Almas-Ali commented 3 months ago

With this proposal Radon will get a Switch...Case...Default statement syntax that developers loves.

Example:

switch(data) {
    case type1 {
        # do something
    }
    case type2 {
        # do something
    }
    ........
    default {
        # default case
    }
}

Without default type will also be valid type. break statement will also be included with this to handle cases. Free fall will be supported here.

This issue will be edited for any future enhancements until feature completed.

angelcaru commented 3 months ago

I think it would be better without the break (maybe there would be a special fallthrough keyword like in Jai) since forgetting it seems to be one of the most common mistakes devs make. This would also allow to break out of loops from within switch statements, like:

while true {
    cmd = input("> ")
    switch cmd {
        ...
        case "exit" {
            break # The `break` in this case would break out of the loop
        }
    }
}
Almas-Ali commented 3 months ago

Ok. Proposal accepted. 👍🏻