O'Reilly logo

Microsoft®C# Programming for the absolute beginner by Andy Harris

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using a While Loop

For loops are good for repeating things a certain number of times; however, in some of your programs, though, you won’t know how many times something is going to happen. In these instances, you need a while loop. For example, you might need a program to continue asking a question until the user gets the correct answer, or you might write a card program that continues drawing cards until it pulls an ace. In either case, you don’t know beforehand how many times the loop will occur, so a while loop is the best solution for this type of situation.

It is possible to use for loops for any kind of looping situation, but using one for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required