While loop (While(a))

The while loop

what does the while loop do? The while loop runs a body of code if the bool value, a, is true and continues running it until a is false. You can also use the values true and false to make the loop run forever or never run.

how do we use the While loop? The method for using the loop is: While(a) { body; } "a" refers to the variable needed to run the function. "body" refers to the code that the loop runs.

Example: While(true) { Console.WriteLine("Hello"); } this loop will output "Hello" to the console forever.

Last updated

Was this helpful?