Chapter 11. Iteration and flow control

This chapter deals with the basic issue of iteration (looping) and flow control in C#.

Like Java

  • In C#, the while (in while loops), do and while (in do...while loops), and for (in for loops) keywords work in exactly the same way as in Java.

  • You can break and continue from within loops to terminate iteration prematurely (except that you cannot use them with labels).

Unlike Java

Flow control in C# is very much the same as Java, except for:

  • a new and useful foreach keyword;

  • some changes to how switch-case is used;

  • C# retains the goto keyword; [1]

    [1] goto is a reserved word in Java, but has no functionality. The usage of goto in C/C++ has often been criticized as poor structural programming. Use it with care in ...

Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.