Web site construction - 122 Control Structures: Part 1 Chapter 4 1

122 Control Structures: Part 1 Chapter 4 1 // Fig. 4.14: Increment.cs 2 // Preincrementing and postincrementing 3 4 using System; 5 6 class Increment 7 { 8 static void Main( string[] args ) 9 { 10 int c; 11 12 c = 5; 13 Console.WriteLine( c ); // print 5 14 Console.WriteLine( c++ ); // print 5 then postincrement 15 Console.WriteLine( c ); // print 6 16 17 Console.WriteLine(); // skip a line 18 19 c = 5; 20 Console.WriteLine( c ); // print 5 21 Console.WriteLine( ++c ); // preincrement then print 6 22 Console.WriteLine( c ); // print 6 23 24 } // end of method Main 25 26 } // end of class Increment 5 5 6 5 6 6 Fig. 4.14 The difference between preincrementing and postincrementing. The program displays the value of c before and after the ++ operator is used. The decrement operator (–) works similarly. Good Programming Practice 4.8 For readability, nary operators should be placed next to their operands, with no intervening spaces. Line 17, Console.WriteLine(); // skip a line uses Console.WriteLine to output a blank line. If Console.WriteLine receives no arguments, it simply outputs a newline character. The arithmetic assignment operators and the increment and decrement operators can be used to simplify program statements. For example, the three assignment statements in Fig. 4.11 (lines 22, 25 and 27)
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision mysql5 web hosting services

Leave a Reply