How to use "break" statement to come out of main function in one of the scripts?

Saurabh8
Kilo Expert

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

 

 

1 ACCEPTED SOLUTION

Thank you Saurabh! 

View solution in original post

9 REPLIES 9

if(yourcondition)
   return;

Thank you Upender!

Hi,

Please check below code

function counter (count)
{
for(var i=0;i<parseInt(count);i++)
{
if(i==5)
{
return;
}
gs.print(parseInt(count)+"::"+i)
}
}

counter(18);

 

It will only print index upto 4

 

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

Thank you Saurabh! 

Hi,

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