Join Bruce Van Horn for an in-depth discussion in this video Do and do-while loops, part of C# Essential Training: 2 Flow Control, Arrays, and Exception Handling.
- [Instructor] The third kind of loop C Sharp,…and I actually realize at this stage…that I've lied to you a little bit.…There are actually four that are common in C Sharp,…and I think in a minute you'll forgive me for miscounting.…Those will be the while loop and the do while loop.…They are surprisingly similar.…Let's take a look at what these look like.…We'll start with the while loop.…I'll say public int, and I'll call this While Loop.…A while loop will just effectively do the same thing…that we did earlier with our for loop.…We're just going to add the numbers from zero to 99.…
Let's do var sum and set it equal to zero.…When you're working with a while loop,…it's very common to initialize a variable called counter.…You'll see why almost immediately.…Our condition looks a little bit like this.…We'll say while counter less than a hundred.…Then for the body, if we want to do the exact same thing…we've been doing so far.…We'll do sum plus equals counter.…Then, well do counter plus plus.…
Don't forget to put your incrementer in there,…
AuthorBruce Van Horn
- Writing unit tests in C#
- Working with simple and multidimensional arrays
- Managing ordered and unordered data with lists
- Evaluating conditions with if-else statements
- Using OR, AND, and NOT operators
- Building loops
- Debugging and handling exceptions
- Creating the final build of your C# project
Skill Level Beginner
C# Object-Oriented Programming Tips and Trickswith Jesse Freeman58m 39s Intermediate
1. Unit Testing and Test-Driven Development
2. Arrays and Collections
3. Flow Control
4. Exception Handling
5. Getting to Production
Next steps1m 57s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.