1
Answer

do- while loop help?

anndy smaals

anndy smaals

6y
875
1
do a while loop such that if i is odd its value is doubled, and if i is even its value is incremented.
Do this while i is less that or equal to 30. Count the number of times the loop is executed and store that value in the count variable.
 
using System;

namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
int i = 1; int count = 0;
do
{
count++;
i = i;
i++;
} while (i<=30);

Console.WriteLine("The loop repeated " + count + " times and now i is " + i);
}
}
}

 
Answers (1)