C# While Loop - c# - c# tutorial - c# net




C# While Loop

Learn c# - c# tutorial - C# While Loop - c# examples - c# programs

What is While loop in C#?

  • In C#, the while statement executes a statement or a block of statements until a specified expression evaluates to false
   C while loop

Syntax:

while (condition is true) 
{
    code will be executed;
}
click below button to copy the code. By - c# tutorial - team
if else while loop in c#

if else while loop in c#

C# Sample Code - C# Examples:

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;

namespace wikitechy_while_loop
{
classProgram
    {
staticvoid Main(string[] args)
        {
int a = 5;
while (a < 10)
            {
Console.WriteLine("Current value of a is {0}", a);
                a++;
            }
Console.ReadLine();
        }
    }
click below button to copy the code. By - c# tutorial - team
Related Tags: kurs c# , c# programmieren , tutorial c# visual studio , learn programming with c# , c# kurs online , the best way to learn c# , c# tutorial for complete beginners from scratch , tuto c# , manual c#

Code Explanation:

 C while loop structure
  1. In this example, int a = 5is an integer variable.
  2. while(a>10) is the while loop which will continue to run as long as a=5 is less than10. In this example Console.WriteLine,the Main method specifies its behavior with the statement "Current value of a is {0}".WriteLine is a method of the Console class defined in the System namespace. This statement reasons the message"Current value of a is {0}"to be displayed on the screen.
  3. a++; specifies to a =5 will increase by 1 each time the loop runs (a++)variable till 9.
  4. Here Console.ReadLine();specifies to reads input from the console. When the user presses enter, it returns a string.

Sample C# examples - Output :

 C while loop structure output
  1. Here in this output, the while loop will continue to run as long as a=5 is less than 10 which will increase by 1 each time the loop runs (a++)till 9.


Related Searches to C# While Loop

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×