473,403 Members | 2,222 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,403 software developers and data experts.

is there syntax error in my code


I am getting squggly blue on (i==1) as well as on d.
class Program
{
static void Main(string[] args)
{
string d;
int i;
for (i = 0; i < 12; )
{
i++;
if (i == 1) d = "first";
if (i == 2) d = "second";
if (i == 3) d = "third";
if (i == 4) d = "fourth";
if (i == 5) d = "fifth";
if (i == 6) d = "sixth";
if (i == 7) d = "seventh";
if (i == 8) d = "eighth";
if (i == 9) d = "ninth";
if (i == 10) d = "tenth";
if (i == 11) d = "eleventh";
if (i == 12) d = "twelveth";

Console.WriteLine("\nOn the, {0}, day of Christmas", d);
Console.WriteLine("\nmy true love sent to me\n");
switch (d)
{
case "first":
Console.WriteLine("\nA Partridge in a Pear Tree\n");
case "second":
case "third":
case "fourth":
case "fifth":
case "sixth":
case "seventh":
case "eighth":
case "ninth":
case "tenth":
case "eleventh":
case "twelveth":

case "default":
break;
}
i++;

}
}
}

Sep 27 '06 #1
3 1131

Yes there are errors in your code.

You need a break statement (or some other statement that prevents
fallthrough) after the case "first".

You also can't use d in the switch(d) statement because the compiler
can't know for sure that it definitely has been assigned a value. If
you for example initialize d like this, it will take care of that
error.

string d = null;
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 27 '06 #2
C#leaner <am**********@yahoo.comwrote:
I am getting squggly blue on (i==1) as well as on d.
I don't know why you're getting one on i==1, but using d at the end of
the set of "ifs" is wrong, because it hasn't yet been definitely
assigned a value. I mean, *we* know that one of the "ifs" will have
been true, but the compiler doesn't.

Also, you need a break after the first switch case - you can't fall
through from one case label to another after you've put some code in.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 27 '06 #3

Jon wrote:
C#leaner <am**********@yahoo.comwrote:
I am getting squggly blue on (i==1) as well as on d.

I don't know why you're getting one on i==1,
Yes, that was really weird. It went awy when I just typed in again and
delted the old one.

>but using d at the end of
the set of "ifs" is wrong, because it hasn't yet been definitely
assigned a value. I mean, *we* know that one of the "ifs" will have
been true, but the compiler doesn't.
I was assuming that d was assigned default value initialliy.
>
Also, you need a break after the first switch case - you can't fall
through from one case label to another after you've put some code in.
I planned to.
>
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 29 '06 #4

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

Similar topics

1
by: Steve | last post by:
I just spent waaaaaaaaaaaayy too much time trying to track down an error that was incorrectly reported just now, and I would like to see if someone can explain to me why it was reported that way. ...
29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
5
by: r.nikhilk | last post by:
Hi, Currently, we are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by...
2
by: david | last post by:
Anyone could give me a hand about this syntax error? Thank you. David Source Code: Dim conn As New SqlConnection(strConn) Dim daAngio As New SqlDataAdapter(strSelectStatement, conn) 'Create a...
3
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very...
7
by: Josh | last post by:
I have a lot of except Exception, e statements in my code, which poses some problems. One of the biggest is whenever I refactor even the triviallest thing in my code. I would like python to...
7
by: bryant | last post by:
Hi all. I am new to ASP and working in Expression Web. The following query displays the information I need in the gridview for a single record. SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM",...
4
by: nickyeng | last post by:
i calling this piece of java code in jsp : List<Customer> list = Customer.listby_page(currentRs); ... ... then it gives me the following error:
6
by: muby | last post by:
Hi everybody :) I'm modifying a C++ code in VC++ 2005 my code snippet void BandwidthAllocationScheduler::insert( Message* msg, BOOL* QueueIsFull,
5
Banfa
by: Banfa | last post by:
So I have a little problem, I have a template class and that class contains a template function; now what I want to do is declare that function in the class (or indeed the entire class) as a friend...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.