O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required