Posts Tagged ‘ Iteration Statements ’

Iteration Statements

Let me dig right into some code:

 

Obviously I want some code being executed when I click my Button. But what? Well, first of all I created a temporary variable, that is used to iterate through this code block a couple of times. In this case I have an integer “i” that starts with the value of “0”. The next thought is as long as the value of “i” is less than 10 the code beneath is executed again. The “i++” simply says that each time the value of “i” is increased by “1”. For each new value a new message is created, using the ToString method.

The string “System.Environment.NewLine” is called a Property, in which “System” is the namespace, “Environment” is a class name. NewLine is responsible for starting a new line for each number in the message. Finally, when the conditions are no longer true, meaning, when I iterated through all possible conditions, I move out of that “ for loop” and get the final message:

Not very exciting so far. But when I want to find a certain value, say “7”, then I can iterate through this code block until I have found that value:

Once that condition is met, that code breaks out of that “for loop” and gives the final message.

I start really having fun with C#. Can’t wait to actually develop a real application on my own. For that to happen, I will have to learn more, so be sure that this blog is…

… to be continued…

Advertisements
%d bloggers like this: