Programming: Computer Programming For Beginners: Learn The Basics Of C# (Coding, C Programming, Java Programming, C# Programming, JavaScript, Python, PHP) by Joseph Connor

Programming: Computer Programming For Beginners: Learn The Basics Of C# (Coding, C Programming, Java Programming, C# Programming, JavaScript, Python, PHP) by Joseph Connor

Author:Joseph Connor [Connor, Joseph]
Language: eng
Format: epub, azw3
Publisher: Microsoft
Published: 2016-07-26T22:00:00+00:00


Chapter 5: Loop Your Way Around C#

When you are writing software or applications, you will need to use Loops. This is an essential technique prevalent in all programming languages. A loop can be defined as a sequence of instructions which are repeated continually till a certain predefined condition is met. In simple terms, a block of code is repeated a set number of times till a condition are fulfilled.

Generally, in a loop, a certain process is performed. This can be as simple as fetching a specific data item and modifying it. After it, a condition is checked. For example, a counter can be checked to see if it has reached a specific number. If the number has not been reached, the next instruction for the program is to return to the very first instruction of the sequence. As such, the sequence is repeated. Once the condition has been fulfilled, the instruction will cause the program to proceed to the next set of sequential instructions. It can also branch out from the loop.

There is a special kind of loop known as an infinite loop. In this loop, there is an absence of a functioning exit instruction. As a result, the loop will repeat continually till it is sensed by the operating system which will terminate the program and an error will show. The infinite loop can also be stopped due to the occurrence of some other event. For example, the program can be made to terminate automatically after a specific duration of time.

In C#, you will come across four different kinds of loops. As such, you need to be familiar with them.

The While Loop

The simplest of the four loops in C# is the while loop. In this type of loop, a sequence of instructions will be executed continually as long as the defined condition returns true. It will only exit when the condition returns false. Here is an example to help you understand it.

using System;



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.