Skip to content

Instantly share code, notes, and snippets.

@shibukawa
Last active November 20, 2020 11:27
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shibukawa/315765020c34f4543665 to your computer and use it in GitHub Desktop.
Save shibukawa/315765020c34f4543665 to your computer and use it in GitHub Desktop.
goto for JS
first:
printf("first\n")
goto third;
second:
printf("second\n");
thrid:
printf("third\n");
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;
}
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