Re: Do While loop syntax
- From: "Cor Ligthert [MVP]" <notmyfirstname@xxxxxxxxx>
- Date: Sun, 29 Apr 2007 08:33:44 +0200
Rene,
Just a thought I got reading your code. Why do you use a while loop and not
the easier and better to understand For index in the case of indexes and
enumurating. The while loop is fine to test a real value.
Cor
D
"Rene" <a@xxx> schreef in bericht
news:%23%23MV$SgiHHA.4624@xxxxxxxxxxxxxxxxxxxxxxx
Yes, I though of that too but the thing is that as far as I know, there is
no such thing as a "do" existing by itself so something like the code
below won't compile:
Do
{
/// code goes here
}
Having said that, I would had imagine that the compiler could easily
figure out that a "do" must have a "while" just like a "{" must have a
"}". Therefore anything after a "while" that is part of a "do" should be
treated not being part of the "while"
"Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote
in message news:OTgcnMgiHHA.4516@xxxxxxxxxxxxxxxxxxxxxxx
Rene,
Well, I feel it is necessary because if you didn't terminate, and you
did something like this:
x = 0;
do
{
x = x + 1;
} while (x < 3)
// Ambiguous code block
{
Console.ReadLine();
}
What is the compiler suppose to do? Does it associate the ambiguous
code block with the while statement above it?
That's why the semi-colon is needed.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Rene" <a@xxx> wrote in message
news:eIf$rHgiHHA.1216@xxxxxxxxxxxxxxxxxxxxxxx
Thanks Nicholas,
So are you saying that is not really necessary but the language rules
dictate that you should so therefore you have to? or something like
that?
"Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote
in message news:%23bxIkofiHHA.4704@xxxxxxxxxxxxxxxxxxxxxxx
Rene,
Mostly because the while statement can be used like so:
while (x < 3)
{
}
Because the statement or statement block is not the last part of the
do/while statement, you need the semi-colon.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Rene" <a@xxx> wrote in message
news:%23SSZAjfiHHA.4496@xxxxxxxxxxxxxxxxxxxxxxx
Quick question, what is the point for forcing the semicolon at the end
of the while statement? See example below:
x = 0;
do
{
x = x + 1;
}while (x < 3);
What's the point of having the semicolon after the (x < 3)? Why can't
the compiler figure out that's the end of the while statement without
the need for the semicolon?
Thank you.
.
- References:
- Do While loop syntax
- From: Rene
- Re: Do While loop syntax
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Do While loop syntax
- From: Rene
- Re: Do While loop syntax
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Do While loop syntax
- From: Rene
- Do While loop syntax
- Prev by Date: Re: Remote Desktop (Not trying to reinvent the Wheel)
- Next by Date: Re: Miscellaneous Newbie questions
- Previous by thread: Re: Do While loop syntax
- Next by thread: Re: Do While loop syntax
- Index(es):
Relevant Pages
|