|
-
Jan 3rd, 2009, 11:32 PM
#1
Thread Starter
Frenzied Member
switch
Heya;
Im a newbie in C# and Im trying to loop 5 times in a console app. However the program exits on the second entry. The problem seems to be the For control . Anyone can point out to me the mistake pls/
Code:
namespace ConsoleSwitch
{
class Program
{
static void Main(string[] args)
{
int x;
string colour,str;
string Blue,Red, Yellow ;
Console.WriteLine("Enter the primary colours colour");
colour = Console.ReadLine();
for (x = 1; x <= 5; x++) ;
switch (colour)
{
case "Blue":
Console.WriteLine("Blue is a primary colour");
//str = Console.ReadLine();
break;
case "Red":
Console.WriteLine("Red is a primary colour");
//str = Console.ReadLine();
break;
case "Yellow":
Console.WriteLine("Yellow is a primary colour");
break;
case "White":
Console.WriteLine("White is a primary colour");
break;
case "Black":
Console.WriteLine("Black is a primary colour");
break;
default:
Console.WriteLine("Colour is NOT a primary colour");
//str = Console.ReadLine();
break;
} //end of switch
str = Console.ReadLine();
} //end of For
}
Last edited by angelica; Jan 3rd, 2009 at 11:36 PM.
------------------------------------------------------------------------
If an answer to your question has been helpful, then please, Rate it! 
-
Jan 4th, 2009, 12:25 AM
#2
Re: switch
You have an empty 'for' loop - the semi-colon at the end of the statement is an empty statement that is the only subject of the loop.
-
Jan 4th, 2009, 12:32 AM
#3
Re: switch
As David says. The semicolon after your 'for' statement is the equivalent of Next in VB. If the 'for' loop contains more than one statement then you must enclose those statements in braces to indicate that they constitute a single block.
-
Jan 4th, 2009, 08:26 AM
#4
Thread Starter
Frenzied Member
------------------------------------------------------------------------
If an answer to your question has been helpful, then please, Rate it! 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|