Programming Lessons: Let's learn a little of C# - Lesson 05

in #csharp-forbeginners7 years ago (edited)

Hello Guys


Some days ago I started a new topic. I wanna teach how to program a little. As you probably know I'm a software developer so I wanna bring some of the stuff that I do daily. With this topic I do not wanna do something hard to understand but the basic concepts of programming.

We'll start with a simple topics and the language that we'll use is C#.

About C#

C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg. This tutorial covers basic C# programming and various advanced concepts related to C# programming language.

First of all, if you wanna try the examples that I'll provide you can use this site to program online C#. Alternatively, you can install the free version on Visual Studio, the best tool to program C# here.


asd.jpg

Image Source

Lesson 05:Loops (Part 1)

A loop is a fundamental operation that every programmer need to understand. When you need to execute a piece of code several times, we usually use a loop. There some loops that we can use, but to start this topic I will start talk about the command while.

The command while is the most simple of them all. The definition to command while is:

"It repeats a statement or a group of statements while a given condition is true. It tests the condition before executing the loop body." source

Code


// Example of a structure while in C#
class WhileApplication
{
    static void Main() 
    {
        // initialization of the variable
        int number = 0;

        // Command While with the condition
        while (number < 10) 
        {
            // Text to write in the console
            Console.WriteLine("Current value of number is: {0}.", number);

            // '++' increments on number to the current number
            number++;
        }
        Console.ReadLine();
    }
}

Console


> Current value of number is: 0.
> Current value of number is: 1.
> Current value of number is: 2.
> Current value of number is: 3.
> Current value of number is: 4.
> Current value of number is: 5.
> Current value of number is: 6.
> Current value of number is: 7.
> Current value of number is: 8.
> Current value of number is: 9.
> Current value of number is: 10.
Press a key to continue...

This is a very simple example how you can use the command while. Believe me, it can be very useful on some cases.


The last lessons are here!

Programming Lessons: Let's learn a little of C# - Lesson 01
Programming Lessons: Let's learn a little of C# - Lesson 02
Programming Lessons: Let's learn a little of C# - Lesson 03
Programming Lessons: Let's learn a little of C# - Lesson 04

Hope you enjoy!

@criptomaster
Sort:  

Interesting Good Luck

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 63592.23
ETH 2551.58
USDT 1.00
SBD 2.75