473,327 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Loop Condition Question

I have the following loop in my simple program ...

Do
line = sr.ReadLine()
If Not line Is Nothing Then
linecount = linecount + 1
If line.Length > 0 Then
If line.Chars(0) = "*"c Then
sw.WriteLine(line)
End If
End If
End If
Loop Until line Is Nothing

It works (unless I made a mistake in removing the comments which I did
to avoid line wrap problems).

But I'd rather do something like this

Do While Not (line = sr.ReadLine) Is Nothing
linecount = linecount + 1
If line.Length > 0 Then
If line.Chars(0) = "*"c Then
sw.WriteLine(line)
End If
End If
Loop
But, given the syntax I've used above, the compiler complains about
"(line = sr.ReadLine) " saying "'Is' requires operands that have
reference types, but this operand has the value type 'Boolean'."

Is there a way to do what I am trying to do? Or another way to avoid
checking for the end of file condition twice? I am trying to avoid
use of GoTo. Also, my emphasis is on performance and simplicity, not
elegance.

Thanks, Bob
Nov 21 '05 #1
3 1120
"eBob.com" <eB******@totallyfakeisp.com> schrieb:
It works (unless I made a mistake in removing the comments which I did
to avoid line wrap problems).

But I'd rather do something like this

Do While Not (line = sr.ReadLine) Is Nothing
This sort of syntax is not supported. Because of VB.NET's overloading of
the '=' operator as assignment and comparison operator assignments are not
allowed in the loop's condition.
Is there a way to do what I am trying to do? Or another way to avoid
checking for the end of file condition twice? I am trying to avoid
use of GoTo.


Reading a text file line-by-line or blockwise with a progress indicator
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
Herfried,

I wanted to be sure that you did not find a solution.
You mean that there should be for *assignment* in this cases something as an
== statement. That would be logical in my opinion. You know something extra
only in this situation.

:-)

Cor
Nov 21 '05 #3
Thank you Herfried. And Wow! An answer on a Sunday and within minutes of
when I posted my question! I think that I will use the StreamReaeder.Peek
method which I learned about in the reference you included.

Thanks, Bob
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uI*************@tk2msftngp13.phx.gbl...
"eBob.com" <eB******@totallyfakeisp.com> schrieb:
It works (unless I made a mistake in removing the comments which I did
to avoid line wrap problems).

But I'd rather do something like this

Do While Not (line = sr.ReadLine) Is Nothing


This sort of syntax is not supported. Because of VB.NET's overloading of
the '=' operator as assignment and comparison operator assignments are not
allowed in the loop's condition.
Is there a way to do what I am trying to do? Or another way to avoid
checking for the end of file condition twice? I am trying to avoid
use of GoTo.


Reading a text file line-by-line or blockwise with a progress indicator
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=readfile&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Wayne Folta | last post by:
Two observations about PEP-315: 1. It's clever, addresses a definite "wart", and is syntactically similar to try/except. But it's syntax seems like an acquired taste to me. 2. It is a very...
24
by: Andrew Koenig | last post by:
PEP 315 suggests that a statement such as do: x = foo() while x != 0: bar(x) be equivalent to while True:
3
by: zeroDoNotYeSpamtype | last post by:
(I tried to post this earlier, but it seems without success) A similar question to this has been answered many times, to whit the question applying when the index variable of a for loop is...
23
by: Mark Anderson | last post by:
A 'for' loop takes 3 arguments (initialize; test; increment). The 'test' must equate as true or false This doesn't work... x = 5; for (y=1; (y==5); y+=1) { alert(x * y); } ...nor does... x...
6
by: Shill | last post by:
I have several questions. In C, AFAIU, a for loop is just syntactic sugar for a while loop. for (i1; i2; i3) i4; is equivalent to i1 while (i2) {
3
by: Ben R. | last post by:
In an article I was reading (http://www.ftponline.com/vsm/2005_06/magazine/columns/desktopdeveloper/), I read the following: "The ending condition of a VB.NET for loop is evaluated only once,...
6
by: John Pass | last post by:
What is the difference between a While and Do While/Loop repetition structure. If they is no difference (as it seems) why do both exist?
8
by: Jim Langston | last post by:
There's the thing about iterating though a map or vector when you may delete one of the elements, where you simply assign the iterator to the map.erase() statement or increment it if you don't. ...
16
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of...
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.