Цикл Do-While
The do-while loop is similar to the while loop however it executes the specified code block first and then checks the condition hence it always executes the code block at least once even if the condition is false.
Following is the syntax of the do-while loop:
do {
// code to be executed
} while (condition);
Let's consider the practical example:
main.cs
1234567891011121314using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { do { Console.WriteLine("Hello World"); } while(1 < 0); } } }
The above code outputs "Hello World" even though the condition 1 < 0 is false. This will become more clear by looking at the flow diagram of the do-while loop:
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Can you explain why the code block executes at least once in a do-while loop?
Can you show a practical example of a do-while loop in JavaScript?
Can you describe the flow diagram of the do-while loop?
Awesome!
Completion rate improved to 1.59
Цикл Do-While
Свайпніть щоб показати меню
The do-while loop is similar to the while loop however it executes the specified code block first and then checks the condition hence it always executes the code block at least once even if the condition is false.
Following is the syntax of the do-while loop:
do {
// code to be executed
} while (condition);
Let's consider the practical example:
main.cs
1234567891011121314using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { do { Console.WriteLine("Hello World"); } while(1 < 0); } } }
The above code outputs "Hello World" even though the condition 1 < 0 is false. This will become more clear by looking at the flow diagram of the do-while loop:
Дякуємо за ваш відгук!