VBScriptFor questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
For Counter = 1 to 10
To [BREAK] out of the "For...Next" Loop, you will want to insert a Code Sequence. Most likely with some sort of User Input Sequence such as with the InputBox Statement.
For Counter = 1 to 10
strCounter = InputBox("?Do you want to Continue?")
If strCounter = "" Then
Counter = 11
A better method would be to use a MsgBox "?Do you want to Continue?" with the "VbYesNo" Constant; as well as, the "VbYes" and "VbNo" Constants in place of the InputBox Sequence; but, I'm not familiar enough with VBScript to write such a sequence at this time.
I am new to VBScript; thus, I only know how to use InputBox for User Inputs in VBScript Codes at this time.
With GW-BASIC, all you needed was a GOTO Statement to [BREAK] out of the "For...Next" Loops because all the Command Lines were numbered.
With GW-BASIC, you could also use the INKEY$ Statement to [BREAK] out of the "For...Next" Loop.
I haven't tested out my Input Sequence; thus, if you get a "Subscript Out Of Range" Error, you should change the Counter = 11 Command Line to Counter = 10.
Last edited by Tandy1000SL GW-BASIC; April 22nd, 2009 at 05:43 AM.
What the Original Poster wanted was to be able to Press a [KEY] to Break a "For...Next" Loop.
I'm sorry, but you are showing your ignorance of other programming languages when you say that.
I understand you think he was talking about pressing some kind of "break" key, but no, he wasn't.
for ( var i = 1; i <= 100; ++i )
document.write("This is iteration " + i + "<br />" );
if ( i > 17 ) break;
That loop will *NOT* execute 100 times, as you might think from reading the for line.
Instead, it will execute 18 times, because on the 18th iteration the variable i is indeed greater than 17 and the break keyword says "exit from the enclosing loop."
And *THAT* is what the original poster in this thread meant when he asked if there is any VBScript equivalent of the JAVA keyword break. (And Java also has a continue keyword which he was asking about, at the same time.)
And, yes, the EXIT FOR and EXIT DO keywords are the closest equivalents, in VBScript and in VB6 and in VB.NET, of the Java break keyword.
Well, that's what I first said to Tandy. But, really, this hopefully *IS* serving to make him rethink what he thought he knew about VBScript. So in that sense, it's up-to-date. Clearly he needs help learning the fundamentals of the language.