What is the output of the following program? [
Explain the working of the while loop in this program as per
your
understanding.
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int number = 100;
while (true) {
Console.WriteLine(number);
number+=100;
if (number <= 1000)
continue;
else
break;
}
Console.ReadLine();
}
}
}
In the given program, the variable number is declared and initialized with value 100. After that, a while loop structure is started which is a forever loop(only stops with break or any other exit condition). Inside the loop, the following operations takes place in order:
Console.ReadLine() method is used to pause the execution after displaying all the values of the variable number, that is from 100 to 1000. The executed code and the corresponding output are as follows:
using System.IO;
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int number = 100;
while (true) {
Console.WriteLine(number);
number+=100;
if (number <= 1000)
continue;
else
break;
}
Console.ReadLine();
}
}
}
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.