By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,626 Members | 2,202 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,626 IT Pros & Developers. It's quick & easy.

"continue" key word equivalent in VB

P: n/a
is there an equivalent key word for C++'s "continue" in VB (.net) in this
context?
CString szLine;
szLine = myReader.ReadLine();
while ( !szLine.IsEmpty() )
{
if ( szLine(0) == '-' )
{
szLine = myReader.ReadLine();
continue; // <-- HERE, so if szLine starts with "-" then
// the rest of this loop is not executed this
time round...
}

szLine = myReader.ReadLine();

//
// rest of the loop code
//

}
thanks!
Daniel.
Nov 16 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
Hello,

"Daniel Bass" <da********@NOSPAMpostmaster.co.uk> schrieb:
is there an equivalent key word for C++'s "continue"
in VB (.net) in this context?


No.

HTH,
Herfried K. Wagner
--
MVP VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 16 '05 #2

P: n/a
Cor
Herfried,
Are you sure is it in that equivalent not something as exit while loop
But when you say so .................................................
Cor
Nov 16 '05 #3

P: n/a
try useing break to drop out of the loop
"Daniel Bass" <da********@NOSPAMpostmaster.co.uk> wrote in message
news:uu****************@TK2MSFTNGP12.phx.gbl...
is there an equivalent key word for C++'s "continue" in VB (.net) in this
context?
CString szLine;
szLine = myReader.ReadLine();
while ( !szLine.IsEmpty() )
{
if ( szLine(0) == '-' )
{
szLine = myReader.ReadLine();
continue; // <-- HERE, so if szLine starts with "-" then
// the rest of this loop is not executed this
time round...
}

szLine = myReader.ReadLine();

//
// rest of the loop code
//

}
thanks!
Daniel.

Nov 16 '05 #4

P: n/a
Hello,

"Brian Henry" <br******@adelphia.net> schrieb:
try useing break to drop out of the loop


In VB .NET?!

HTH,
Herfried K. Wagner
--
MVP VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 16 '05 #5

P: n/a
Daniel,
The closest you will come to a Continue in VB.NET is to use the Goto
keyword.

Something like:
szLine = myReader.ReadLine()
Do Until szLine Is Nothing
If szLine.Chars(0) = "-"c Then
szLine = myReader.ReadLine()
GoTo continue
End If
szLine = myReader.ReadLine()
If szLine is Nothing Then Exit Do
'
' rest of the loop code
'
continue:
Loop

Personally I would put a single ReadLine after the Continue, avoiding the
third ReadLine. Also I would consider having the 'rest of the loop code' in
the Else block of the If comment block. Or change the If comment to If Not
comment rest of loop code.

Hope this helps
Jay

"Daniel Bass" <da********@NOSPAMpostmaster.co.uk> wrote in message
news:uu****************@TK2MSFTNGP12.phx.gbl...
is there an equivalent key word for C++'s "continue" in VB (.net) in this
context?
CString szLine;
szLine = myReader.ReadLine();
while ( !szLine.IsEmpty() )
{
if ( szLine(0) == '-' )
{
szLine = myReader.ReadLine();
continue; // <-- HERE, so if szLine starts with "-" then
// the rest of this loop is not executed this
time round...
}

szLine = myReader.ReadLine();

//
// rest of the loop code
//

}
thanks!
Daniel.

Nov 16 '05 #6

P: n/a
> is there an equivalent key word for C++'s "continue" in VB (.net) in this
context?


There's always another way of writing it - how about instead of trying to =
'-', you test not equals to '-'

eg
while(not empty)
{
if(last char != '-')
{
rest of code in here
}
}

reads better too i think
Nov 16 '05 #7

P: n/a
> There's always another way of writing it - how about instead of trying to
=
'-', you test not equals to '-'

eg
while(not empty)
{
if(last char != '-')
{
rest of code in here
}
}

reads better too i think


I'm afraid I have to disagree, nested parenthesis (or begin/end's in a VB
case) isn't that pleasing to the eye...

if your reading through the code, seeing a continue near the start signifies
a conditional loop, but seeing two sets of begin/end's can get confusing
when you're looking at something like

function ...()
{
while m_bWhatever
{
if ( my condition is true )
{
... code here ...
}
}
}

the last }'s can get confusing, especially in large multilevel functions.

it's all about preference I guess! ;o)

Thanks for your comment.
Nov 16 '05 #8

P: n/a
Cor
Jay,
Sorry, but this is terrible, all the work of Dijkstra (he died last year) is
done with what you wrote (while your examples are normaly so good).
szLine = myReader.ReadLine()
Do Until szLine Is Nothing
If szLine.Chars(0) = "-"c Then
szLine = myReader.ReadLine()
' GoTo continue /// removed
' End If /// removed
Else ' that is all Cor inserted
szLine = myReader.ReadLine()
If szLine is Nothing Then Exit Do
'
' rest of the loop code
'
' continue: ////removed
Loop
In C you have to keep track of the {} of course therefore escaping is very
easy.
That is exactly the same without using low level coding.
Cor
Nov 16 '05 #9

P: n/a
Cor
Adam,
Sorry, I Did not see so fast your messag that was the same as mine
Cor

Nov 16 '05 #10

P: n/a
Hello Daniel,

"Daniel Bass" <da********@NOSPAMpostmaster.co.uk> schrieb:
if your reading through the code, seeing a continue near the start signifies a conditional loop, but seeing two sets of begin/end's can get confusing
when you're looking at something like

function ...()
{
while m_bWhatever
{
if ( my condition is true )
{
... code here ...
}
}
}

the last }'s can get confusing, especially in large multilevel functions.


\\\
function ...()
{
while m_bWhatever
{
if ( my condition is true )
{
... code here ...
} // if
} // while
} // function
///

;-)))

HTH,
Herfried K. Wagner
--
MVP VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 16 '05 #11

P: n/a
Hello Cor,

"Cor" <no*@non.com> schrieb:
In C you have to keep track of the {} of course therefore escaping is very
easy.
That is exactly the same without using low level coding.


Mhmmm. I love GoTo.

HTH,
Herfried K. Wagner
--
MVP VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 16 '05 #12

P: n/a
Cor,
I was only demonstrating the continue.

The obscure last paragraph stated what I would actually do.
Personally I would put a single ReadLine after the Continue, avoiding the
third ReadLine. Also I would consider having the 'rest of the loop code' in the Else block of the If comment block. Or change the If comment to If Not
comment rest of loop code.
As having the 'rest of the loop code in the else block' would avoid the
goto altogether. I should have added "And avoid the goto altogether".

However there are some loops used for parsing where you need the Goto, no
clean way around it. This example is simply to simple to demonstrate it.
There are ways to avoid these Goto/Continue statements however then you
start introducing intricate control variables with strange nested ifs, whose
only purpose is to avoid the goto. Where a single goto would avoid it.

Thanks for clarifying.

Jay
"Cor" <no*@non.com> wrote in message
news:3f***********************@reader21.wxs.nl... Jay,
Sorry, but this is terrible, all the work of Dijkstra (he died last year) is done with what you wrote (while your examples are normaly so good).
szLine = myReader.ReadLine()
Do Until szLine Is Nothing
If szLine.Chars(0) = "-"c Then
szLine = myReader.ReadLine()
' GoTo continue /// removed
' End If /// removed
Else ' that is all Cor inserted
szLine = myReader.ReadLine()
If szLine is Nothing Then Exit Do
'
' rest of the loop code
'
' continue: ////removed
Loop
In C you have to keep track of the {} of course therefore escaping is very
easy.
That is exactly the same without using low level coding.
Cor

Nov 16 '05 #13

P: n/a
Cor wrote:

Jay,
Sorry, but this is terrible, all the work of Dijkstra (he died last year) is
done with what you wrote (while your examples are normaly so good).


Dijkstra had a point but his generalization was about as valuable as
most (which is, often but not universally). I believe there have been
studies which have shown that flow control in loops is a valuable use
of goto -- it can produce cleaner and more maintainable code.

And let's be honest -- there are language features (most notably the
various "exit" statements) that are thinly disguised gotos.

--
Craig Powers
MVP - Visual C++
Nov 16 '05 #14

P: n/a
Daniel Bass wrote:

is there an equivalent key word for C++'s "continue" in VB (.net) in this
context?

CString szLine;
szLine = myReader.ReadLine();
while ( !szLine.IsEmpty() )
{
if ( szLine(0) == '-' )
{
szLine = myReader.ReadLine();
continue; // <-- HERE, so if szLine starts with "-" then
// the rest of this loop is not executed this
time round...
}

szLine = myReader.ReadLine();

//
// rest of the loop code
//

}


I think this loop can probably be better cast.

My thought...

CString szLine;

do {
szLine = myReader.ReadLine();

while (!szLine.IsEmpty() && szLine(0) == '-')
szLine = myReader.ReadLine();

if (szLine.IsEmpty()) break;

// etc.
} while (! szLine.IsEmpty() );

Except that this isn't exactly the same -- do you really intend to
unconditionally discard the first line you read? That looks suspicious,
but it can be easily remedied with an initial ReadLine call outside
the loop.

--
Craig Powers
MVP - Visual C++
Nov 16 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.