What is the Jscript counter part of VBScript Exit inside If.. End If 
Author Message
 What is the Jscript counter part of VBScript Exit inside If.. End If

Hello

If a>50 then
    Runthis
    Exit                (//'It goes to outside If clause)
    NoRunthis
End If
Msgbox("Exited")

Is there jscript counter part of VBScript Exit?
break; can be used only inside a loop!
Thank you very much



Sun, 27 Jun 2004 06:14:25 GMT  
 What is the Jscript counter part of VBScript Exit inside If.. End If
There are a few different versions of If-Exit:

The If-Else:

If (a>50) {
  // perform this code if a>50

Quote:
} else {

  // perform this code if a<=50

Quote:
}

The While:

While (a>50) {
  // perform this code if a>50.
  // make sure that the code makes
  // the condition untrue eventually,
  // because if you don't, you'll have
  // a non-stopping loop.

Quote:
}

and the For:

for (a=100; a>50; a--) {
  // this code will execute
  // as long as the second portion of the
  // loop code is true.
  // It is typically used to iterate
  // through the contents of an array.

Quote:
}

FOR loop example:

var theArray=new Array("Rob", "WinglessLight", "Raman", "Eugene", "Chris");

for (loop=0; loop<theArray.length; loop++) {
  document.write("<P>Name " + loop + " is " + theArray[loop] + ".</P>");

Quote:
}

Explanation:
Line 1:Create a new array with the names specified.
Line 3:begin a FOR loop based on the variable "loop".
Line 4:write to the document for every iteration:
 Iteration 1: <P>Name 0 is Rob.</P>
 Iteration 2: <P>Name 1 is WinglessLight.</P>
 Iteration 3: <P>Name 2 is Raman.</P>
 Iteration 4: <P>Name 3 is Eugene.</P>
 Iteration 5: <P>Name 4 is Chris.</P>
 Iteration 6: (loop is no longer less than the length of theArray.  FOR loop
exits without executing the lines.)
Line 5:close the FOR loop.

Note that if you're using this in ASP, you would use "Response.write()"
instead of "document.write()".

--Robert Paveza


Quote:
> Hello

> If a>50 then
>     Runthis
>     Exit                (//'It goes to outside If clause)
>     NoRunthis
> End If
> Msgbox("Exited")

> Is there jscript counter part of vbscript Exit?
> break; can be used only inside a loop!
> Thank you very much



Sun, 27 Jun 2004 13:23:45 GMT  
 What is the Jscript counter part of VBScript Exit inside If.. End If
When I try your script in VBScript, I get "Microsoft VBScript compilation
error: Invalid 'exit' statement". Even if it did work, it seems to be a bad
coding practice. If you don't want NoRunthis to execute, don't call it!

That said, there's a solution for JScript--label the if statement:

  myLabel: if (a>50) {
    Runthis();
    break myLabel;
    NoRunthis();
  }

--
The value of the average conversation could be enormously improved by the
constant use of four simple words: "I do not know." -Andre Maurois

=-=-=
Steve
-=-=-


Quote:
> Hello

> If a>50 then
>     Runthis
>     Exit                (//'It goes to outside If clause)
>     NoRunthis
> End If
> Msgbox("Exited")

> Is there jscript counter part of vbscript Exit?
> break; can be used only inside a loop!
> Thank you very much



Sun, 27 Jun 2004 20:43:38 GMT  
 What is the Jscript counter part of VBScript Exit inside If.. End If
It is break or return.

if (clause){
    return  -->function stops here

Quote:
}

Or

for(){
    break

Quote:
}

Gerald


Quote:
> Hello

> If a>50 then
>     Runthis
>     Exit                (//'It goes to outside If clause)
>     NoRunthis
> End If
> Msgbox("Exited")

> Is there jscript counter part of vbscript Exit?
> break; can be used only inside a loop!
> Thank you very much



Sun, 27 Jun 2004 22:18:33 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. I am trying to Use JScript within VBScript!!!

2. call a jscript-function in the vbscript-part of an asp-page

3. Using vbscript inside jscript

4. MAC IE(all) JScript Inside a dropdown, create by JScript does't work

5. How to leave or exit a JScript?

6. Exiting the JScript Infinite Loop

7. I want to send mail in WSH with JScript source...What am I doing wrong

8. I want to send mail in WSH with JScript source...What am I doing wrong

9. creating a hyperlink with jscript inside?

10. How to use JScript file (using WScript object) inside HTML codeWScript

 

 
Powered by phpBB® Forum Software