goto for JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
first: | |
printf("first\n") | |
goto third; | |
second: | |
printf("second\n"); | |
thrid: | |
printf("third\n"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var destination = "first" | |
topLabel: while (true) { | |
var jump = false; | |
switch (destination) { | |
case "first": // caseがラベル相当 | |
console.log("first"); | |
//ここから | |
destination = "third"; | |
jump = true; | |
break; | |
//ここまでが goto third; | |
case "second": | |
console.log("second"); | |
case "third": | |
console.log("third"); | |
} | |
if (jump) { | |
continue topLabel; | |
} | |
break; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OutJump(Exception): | |
pass | |
outjump = OutJump() | |
destination = "first" | |
while True: | |
try: | |
if destination == "first": | |
print("first") | |
destination = "third" | |
raise outjump | |
elif destination == "second": | |
print("second") | |
elif destination == "third": | |
print("third") | |
except OutJump as e: | |
pass | |
else: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment