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 do…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 :
do < Instr > while ( < Expr > )
< 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;
do
    a -=3;
while (a > 2) 

using System;

class Exercice
{
public static void Main( ) 
{
// avec une instruction simple:
int a =15, b=2 ;
do
a -=b;
while (a+b > 2);
Console.WriteLine("a = " +a+", b = " +b);

Console.WriteLine("--------------------");
// avec un bloc d'instruction :
a =15; b=2 ;
do
{
a -=b;
Console.WriteLine("a = " +a+", b = " +b);
}
while (a+b > 2);
Console.WriteLine("a = " +a+", b = " +b);

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