Updated on Kisan Patel
The while
loop statement executes until the while
condition is true
.
The basic structure of a while loop is-
while(condition) { statement or block of code }
Lets take an example to print 1 to 10. In below example, the while
loop executes until the value of i
is less then 10.
using System; namespace ConsoleApp { class whileloopDemo { static void Main(string[] args) { int i = 1; while (i <= 10) { Console.WriteLine(i); i++; } } } }
The output of the above C# program…