Changes

Jump to: navigation, search

C Sharp Looping - The for Statement

22 bytes added, 15:13, 17 March 2009
no edit summary
In this chapter of [[C Sharp Essentials|C# Essentials]] we will continue looking at flow control in C# applications. In the preceding chapters we have looked in detail at using logical expressions to decide what C# code should be executed. Another aspect of flow control entails the definition of loops. Loops are essentially sequences of C# statements which are to be executed repeatedly until a specified condition (or conditions) are met.
 
== Why Use Loops? ==
It is generally common knowledge that computers are great at performing repetitive tasks an infinite number of times, and doing so very quickly. It is also common knowledge that computers really don't do anything unless someone programs them to tell them what to do. Loop statements are the primary mechanism for telling a computer to perform the be repeated a specific number of times. Suppose, for example, that you have a requirement to add a number to itself ten times. One way to do this might be to write the following C# code:

Navigation menu