Friday 15 January 2010

c# - Using return to exit a loop? -


If I write, do or loop, is it possible to come out of this return keyword?

Example:

  class breakteest {public static zero main (for (int i = 1; i & lt; = 100; i ++) {if (I == 5) ** return; ** console.light line (i);}}}  

I know that returns can be used to exit the statement So, I am curious about this because I have never used it (and can not use my software to write code for testing).

return will exit the current method (main in your example). Use break to exit the loop.


No comments:

Post a Comment