stop a function javascript
function func() {
if (conditionToStopFunction)
return; //Nothing after return will be executed
console.log("Hello World"); //This will not be executed if 'conditionToStopFunction' is true
}
stop a function javascript
function func() {
if (conditionToStopFunction)
return; //Nothing after return will be executed
console.log("Hello World"); //This will not be executed if 'conditionToStopFunction' is true
}
js break out of a function
By using 'return;':
function myfunction(){
if(a == 'stop')
return; //returns Void, ending function
}
Does not work when using a Conditional operator:
let result = 1 == 2 ? "YES" : return; //<--- throws error
c# stop loop in method
/* There is another way to break out of a loop if you use
the return command inside a method/function */
class MainClass {
public static void Main (string[] args) {
UnlockDoor();
// after it hits the return statement,
// it will move on to this method
PickUpSword();
}
static bool UnlockDoor()
{
bool doorIsLocked = true;
// this code will keep running
while (doorIsLocked)
{
bool keyFound = TryKey();
// eventually if this stopping condition is true,
// it will break out of the while loop
if (keyFound)
{
// this return statement will break out of the entire method
return true;
}
}
return false;
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us