Open manoharkakumani opened 2 months ago
Thanks for the PR, just the one question:
I'm not sure I fully understand the use of the fall keyword here, what is it providing that we can't already do?
Thanks for the PR, just the one question:
I'm not sure I fully understand the use of the fall keyword here, what is it providing that we can't already do?
fall is a keyword used within a switch statement to specify that execution should continue to the next case, even if the matching case block completes.
In our language our switch statement is implemented to executed only first matched case block #410. In some sequential scenario you might want to execute code in one case and then continue with the next case, regardless of whether its condition matches.
for example, you are managing subscriptions [ all the premium members should have premium features and basic features whereas basic members should have only basic features]
// before fall keyword
var membership = "premium";
switch(membership) {
case "premium" : {
// premium features + basic features
}
case "basic " : {
// basic features
}
}
// with fall keyword
var membership = "premium";
switch(membership) {
case "premium" : {
// premium features
}
fall case "basic " : {
// basic features
}
}
Thanks for the PR, just the one question: I'm not sure I fully understand the use of the fall keyword here, what is it providing that we can't already do?
fall is a keyword used within a switch statement to specify that execution should continue to the next case, even if the matching case block completes.
In our language our switch statement is implemented to executed only first matched case block #410. In some sequential scenario you might want to execute code in one case and then continue with the next case, regardless of whether its condition matches.
for example, you are managing subscriptions [ all the premium members should have premium features and basic features whereas basic members should have only basic features]
// before fall keyword var membership = "premium"; switch(membership) { case "premium" : { // premium features + basic features } case "basic " : { // basic features } }
// with fall keyword var membership = "premium"; switch(membership) { case "premium" : { // premium features } fall case "basic " : { // basic features } }
I think my confusion comes from the fact that if you always wanted "basic" to run you'd just move it out of the switch:
var membership = "premium";
switch(membership) {
case "premium" : {
// premium features
}
}
// basic features
I'm trying to think of a case currently where you'd need the fall keyword without a ton of additional boilerplate
Thanks for the PR, just the one question: I'm not sure I fully understand the use of the fall keyword here, what is it providing that we can't already do?
fall is a keyword used within a switch statement to specify that execution should continue to the next case, even if the matching case block completes. In our language our switch statement is implemented to executed only first matched case block #410. In some sequential scenario you might want to execute code in one case and then continue with the next case, regardless of whether its condition matches. for example, you are managing subscriptions [ all the premium members should have premium features and basic features whereas basic members should have only basic features]
// before fall keyword var membership = "premium"; switch(membership) { case "premium" : { // premium features + basic features } case "basic " : { // basic features } }
// with fall keyword var membership = "premium"; switch(membership) { case "premium" : { // premium features } fall case "basic " : { // basic features } }
I think my confusion comes from the fact that if you always wanted "basic" to run you'd just move it out of the switch:
var membership = "premium"; switch(membership) { case "premium" : { // premium features } } // basic features
I'm trying to think of a case currently where you'd need the fall keyword without a ton of additional boilerplate
let's consider one more case called "premium+" [ which has some more additional features to premium]. How do you handle it.
Ah so you're saying in that circumstance you could then do something like this?
switch (membership) {
case "premium+": {
// premium+
}
fall case "premium": {
// premium
}
fall case "basic": {
// basic
}
}
Where premium+ would fall into both cases and premium would fall into basic?
Opinions on this @briandowns?
I get the idea behind the addition to the language but I'm not really sure this feature is necessary. I think there are probably better ways to handle those cases. As always, I'll defer to your judgement. :D @Jason2605
What's Changed:
Added a new keyword fall to use it in switch statement to execute the next case in the flow
#
Type of Change:
#
Housekeeping:
#
Screenshots (If Applicable):