killing the execution of code

P

poornibalu

I want to stop the execution of the code when the value of k>100 in
the function

function aa()
{
if (k>100)

{

//command to kill the execution

}
}

I saw the break to break the loop, but I'm trying to just stop the
javascript function from continueing execution. I can work around it
in other ways, but that would require alot of redundant code or
another function, both of which I'd like to avoid.

Please help me with this
 
E

Evertjan.

wrote on 13 dec 2007 in comp.lang.javascript:
I want to stop the execution of the code when the value of k>100 in
the function

function aa()
{
if (k>100)

{

//command to kill the execution

}
}

I saw the break to break the loop, but I'm trying to just stop the
javascript function from continueing execution. I can work around it
in other ways, but that would require alot of redundant code or
another function, both of which I'd like to avoid.

This is contrary to moduled programming, and would be a shame to have
introduced.

I am glad that it is not possible. A function ends when it returns
[something or nothing].

The global program ends, when there is no more global code.

=================================================

That being said, it is simple to do in browser js:

function aa(k) {
if (k>100) {
window.location.href = 'http://cnn.com/';
};
};

Though this is not what you probably ment,
it does what you asked.
 
S

Stevo

I want to stop the execution of the code when the value of k>100 in
the function

function aa()
{
if (k>100)
{
//command to kill the execution
}
}
I saw the break to break the loop, but I'm trying to just stop the
javascript function from continueing execution. I can work around it
in other ways, but that would require alot of redundant code or
another function, both of which I'd like to avoid.
Please help me with this

Have you thought of just using return ?

function aa()
{
if (k>100)
{
return; //command to kill the execution
}
}
 
T

Thomas 'PointedEars' Lahn

gmail.com said:
I want to stop the execution of the code when the value of k>100 in
the function

function aa()
{
if (k>100)

{

//command to kill the execution

}
}

I saw the break to break the loop, but I'm trying to just stop the
javascript function from continueing execution. I can work around it
in other ways, but that would require alot of redundant code or
another function, both of which I'd like to avoid.

return ...

RTFM.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,375
Latest member
FelishaCma

Latest Threads

Top