- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2021 11:50 PM
Hi All
Need a small help to understand as to where should I apply "break" statement, so that within the mainfunction(), once if condition gets executed it breaks out entirely out of the mainfunction()
Need to make sure it doesn't hamper the flow of the mainfunction() after the if condition is executed.
Can something be done in the name() ?
//Main Function
mainfunction(){
....
....
....
if( condition ) {
this.__name();
break; // Here Will it work?
}
.....
.....
......
}
__name: function(){
//perform some actions
}
Thanks and Regards
Saurabh Chatterjee
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2021 08:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2021 11:56 PM
Hi, break; needs to be used within a switch or loop, so I would expect your example to be fine
https://www.w3schools.com/jsref/jsref_break.asp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2021 12:07 AM
Yes.if the above code is in loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2021 12:36 AM
Hi,
If you want to come out of function you should be using "return" statement. "break" statement is used in loops and switch cases.
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
Regards,
Saurabh
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2021 12:59 AM
Hey Saurabh
Could you please help me with an example using the above code ( where exactly I need to put my return statement ) ?
Regards
Saurabh