Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Practicing Do-While Loop | Loops
course content

Зміст курсу

C# Basics

Practicing Do-While LoopPracticing Do-While Loop

There are two variables called numberA and numberB. The program is supposed to count from numberA to numberB.

If numberA is bigger than numberB then it should decrement the value of numberA every step. If numberA is smaller than numberB then it should increment numberA every step.

Also write the appropriate condition to end the loop.

cs

main.cs

1. The loop should continue as long as the numbers are NOT equal (`!=`).

using System;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int numberA = 10;
            int numberB = 1;
            do
            {
                if (numberA > numberB)
                {
                    numberA--;
                }
                else if (numberA < numberB)
                {
                    numberA++;
                }
                Console.WriteLine(numberA);
            } while (numberA != numberB);
        }
    }
}
      

Все було зрозуміло?

Секція 4. Розділ 5
course content

Зміст курсу

C# Basics

Practicing Do-While LoopPracticing Do-While Loop

There are two variables called numberA and numberB. The program is supposed to count from numberA to numberB.

If numberA is bigger than numberB then it should decrement the value of numberA every step. If numberA is smaller than numberB then it should increment numberA every step.

Also write the appropriate condition to end the loop.

cs

main.cs

1. The loop should continue as long as the numbers are NOT equal (`!=`).

using System;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int numberA = 10;
            int numberB = 1;
            do
            {
                if (numberA > numberB)
                {
                    numberA--;
                }
                else if (numberA < numberB)
                {
                    numberA++;
                }
                Console.WriteLine(numberA);
            } while (numberA != numberB);
        }
    }
}
      

Все було зрозуміло?

Секція 4. Розділ 5
some-alt