O'Reilly logo

Visual C#® 2012: How to Program, Fifth Edition by Harvey Deitel, Paul Deitel

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

6.3. for Repetition Statement

Section 6.2 presented the essentials of counter-controlled repetition. The while statement can be used to implement any counter-controlled loop. C# also provides the for repetition statement, which specifies the elements of counter-controlled-repetition in a single line of code. In general, counter-controlled repetition should be implemented with a for statement. Figure 6.2 reimplements the app in Fig. 6.1 using the for statement.

 1   // Fig. 6.2: ForCounter.cs  2   // Counter-controlled repetition with the for repetition statement.  3   using System;  4  5   public class ForCounter  6   {  7      public static void Main( string[] args )  8      {  9         // for statement header ...

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