Getsuyodev, Programming is mainly used when constructing an application. Programming requires knowledge of application domains, algorithms, and programming language expertise. Programming can be developed in different logic based on developer knowledge.

C Sharp – Itération while( )

Programmation en C# (C Sharp)



Il s’agit ici d’une des 4 instructions de boucles du langage C# ( while ( ), do…while ( ), for ( ) , foreach ( ) )

Syntaxe :
while ( < Expr > ) < Instr > ;
< Expr > est une expression boolénne et < Instr > est un bloc d’instructions ou une instruction simple

Exemple :
La boucle  qui suit, décrémente 5 fois la variable “a” (a=12, a=9, a=6, a=3, a=0) jusqu’à ce que le test “a>2” renvoie la valeur false ce qui arrête la boucle.

int a =15;
while (a > 2) {
    a -=3;
}


using System;

class Exercice
{
public static void Main( ) 
{
int a =15, b=2 ;
while (a > 2)
{
a -=b;
Console.WriteLine("a = " +a);
}
Console.WriteLine("--------------------");

a =10; 
b = 10;
while (a +b> 0)
{
int c=1;
Console.WriteLine("-----while interne-------");
while ( c<10)
{
c++;
a--;
b--;
Console.WriteLine("a = " +a+", b = " +b+", c =  " +c);
}
}
Console.ReadLine();
}
}



Comments are closed, but trackbacks and pingbacks are open.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More