Uploaded by Vibitha SureshKumar

while and do while

advertisement
using System;
class HelloWorld {
static void Main() {
Console.WriteLine("Hello World");
int counter=1;
do
{
Console.WriteLine($"{counter} {counter*12}");
counter=counter+1;
}while(counter<=10);
}
}
Console.WriteLine("Hello World");
int start=50;
int stop=80;
int sum=0;
do{
sum=sum+start;
start=start+1;
}while(start<stop);
Console.WriteLine($"The sum is {sum}");
}
}
using System;
class HelloWorld {
static void Main() {
Console.WriteLine("Hello World");
int start=50;
int stop=80;
int sum=0;
do{
sum=sum+start;
Console.WriteLine($"The sum in the loop is {sum}");
start=start+1;
}while(start<stop);
Console.WriteLine($"The sum {sum}");
}
}
int sum=0;
bool tocontinue=true;
do
{
Console.Write("Enter a positive number:");
int number=Convert.ToInt32(Console.ReadLine());
if(number>=0)
sum=sum+number;
else
tocontinue=false;
}while(tocontinue);
Console.WriteLine($"The sum is {sum}");
}
}
}
using System;
class HelloWorld {
static void Main() {
Console.WriteLine("Hello World");
int counter=0;
while(counter<5)
{
Console.WriteLine("Hello");
counter++;
}
}
}
using System;
class HelloWorld {
static void Main() {
Console.WriteLine("Hello World");
int counter=0;
for(;;)
{
Console.WriteLine("Hello");
counter++;
if(counter==5)
{
break;
}
}
}
}
int start = 80;
int stop = 20;
int increment = -10;
while(start>=stop)
{
Console.WriteLine(start);
start += increment;
} }
}
int sum = 0;
for(int counter=0; counter<5; counter++)
{
Console.WriteLine("Hello");
sum += counter;
Console.WriteLine($"{sum}");
}
Console.WriteLine($"After the loop {sum}");
Download