about continue statement

W

W. Jack

Hello,
<%@ Language=JScript %>
<%
var a=0;
while(a<20)
{
a++;
if (a==10)
continue abc;
Response.Write ("eee");
abc:
}
%>
but run this script,is error.IE is Japanese,error's means label no defined.
Thank you
 
A

Aaron Bertrand [MVP]

I get:

Microsoft JScript compilation error '800a0402'
Label not found
/js.asp, line 8
continue abc;
------------^

I don't believe you can use a label, just the continue command (which looks
like it will accomplish the same thing). continue tells the loop to move to
the next iteration without executing the code that follows. In VBScript
you'd have to nest an if/else or select case. In JScript, if you want to
skip statements, you won't use continue, you'd have to use if ...

Try this instead:

<%@ Language=JScript %>
<%
var a=0;
while(a<20)
{
a++;
if (a==10) continue;
Response.Write ("eee");
}
%>
 
W

W. Jack

Thank you for your help!
But,I want use a statement in JScript,which like C language's goto;

<%@ Language=JScript %>
<%
var a=0,b=7;
while(a<20)
{
a++;
if (a==b)
continue abc;
}
Response.Write ("eee");
abc:
%>
I know this script is error.How can use a statement like C's goto?
Thank you
 
A

Aaron Bertrand [MVP]

Like I said, I don't think you can use it the way you're trying (I assume
you want to put code under abc: so that you can skip the response.write line
but stay in the same iteration). Continue is used to move to the next
iteration; it is not a goto, and you cannot use it to move to different
lines of code within the same scope. Have you considered using IF like most
people would?
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top