Console App

unreachable code?

Page 1 of 1

4 Replies - 536 Views - Last Post: 30 November 2009 - 04:47 AM Rate Topic: -----

#1 b.ihde  Icon User is offline

  • D.I.C for life
  • member icon

Reputation: 44
  • View blog
  • Posts: 1,070
  • Joined: 29-September 08

Console App

Posted 30 November 2009 - 03:49 AM

Hey all!

It s time to ask for some help ;)

I m creating a simple match console application but for some reasen i don t know why some code is not reachable insade a do-while loop..

Maybe you can help me out..

My code:

do
			{
				Zahl--;
				if ((Zahl % 2) != 0)
				{
					continue;
					Console.WriteLine("gerade"); // Console is not reachable
				}
				else
				{
					break;
					Console.WriteLine("ungerade"); // Console is not reachable
				}
			}
			while (Zahl > 1);



Thanks!!

Ben

Is This A Good Question/Topic? 0
  • +

Replies To: Console App

#2 kstr  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 60
  • Joined: 19-October 09

Re: Console App

Posted 30 November 2009 - 04:00 AM

View Postb.ihde, on 30 Nov, 2009 - 02:49 AM, said:

Hey all!

It s time to ask for some help ;)

I m creating a simple match console application but for some reasen i don t know why some code is not reachable insade a do-while loop..

Maybe you can help me out..

My code:

do
			{
				Zahl--;
				if ((Zahl % 2) != 0)
				{
					continue;
					Console.WriteLine("gerade"); // Console is not reachable
				}
				else
				{
					break;
					Console.WriteLine("ungerade"); // Console is not reachable
				}
			}
			while (Zahl > 1);



Thanks!!

Ben



The break statement terminates the closest enclosing loop or switch statement in which it appears. Control is passed to the statement that follows the terminated statement, if any.


This means that this code:
Console.WriteLine("ungerade"); // Console is not reachable

will never be executed


you have to first do console.writeline, then break.




... this applies to your continue statement as well...
Was This Post Helpful? 1
  • +
  • -

#3 b.ihde  Icon User is offline

  • D.I.C for life
  • member icon

Reputation: 44
  • View blog
  • Posts: 1,070
  • Joined: 29-September 08

Re: Console App

Posted 30 November 2009 - 04:04 AM

Ahhh ya sure!

Man, i sometime s i just don t know what i m doing.. ;)

Thank you very much!!

Ben
Was This Post Helpful? 0
  • +
  • -

#4 kstr  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 60
  • Joined: 19-October 09

Re: Console App

Posted 30 November 2009 - 04:38 AM

View Postb.ihde, on 30 Nov, 2009 - 03:04 AM, said:

Ahhh ya sure!

Man, i sometime s i just don t know what i m doing.. ;)

Thank you very much!!

Ben



The smallest errors create the most loss of time. I can spend an hour searching an error when all i have to do is add () :P
Was This Post Helpful? 0
  • +
  • -

#5 b.ihde  Icon User is offline

  • D.I.C for life
  • member icon

Reputation: 44
  • View blog
  • Posts: 1,070
  • Joined: 29-September 08

Re: Console App

Posted 30 November 2009 - 04:47 AM

View Postkstr, on 30 Nov, 2009 - 11:38 AM, said:

View Postb.ihde, on 30 Nov, 2009 - 03:04 AM, said:

Ahhh ya sure!

Man, i sometime s i just don t know what i m doing.. ;)

Thank you very much!!

Ben



The smallest errors create the most loss of time. I can spend an hour searching an error when all i have to do is add () :P



Hehe ya, so true^^
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1