anndy smaals

anndy smaals

  • NA
  • 24
  • 3.9k

do- while loop help?

Dec 17 2018 12:49 PM
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)