Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ while Loop | Loops
C# Basics

bookwhile Loop

メニューを表示するにはスワイプしてください

A while loop is similar to a for loop, however, it is used when we need to execute a block of code repeatedly based on a condition. The syntax of a while loop is simpler than that of a for loop:

while (condition) {
    // code to execute
}


Let's consider the practical example:

main.cs

main.cs

copy
12345678910111213141516
using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { int i = 0; while(i < 5) { Console.WriteLine(i); i++; } } } }

Although the while loop may seem very similar to the for loop at first, In more advanced levels of programming the difference becomes apparent. We might explore the usage of different kinds of loops in the Arrays section.

Note

We can write true as the condition of a while-loop to create an infinite loop. But it's not recommended to use.

main.cs

main.cs

copy
123
while(true) { Console.WriteLine("Hello World"); }
question mark

How many iterations will the following loop have?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 4.  4

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 4.  4
some-alt