02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Do...While(condition)

What if you want your loop to run at least one time no mater what? ok lets do it using do..while

Video Transcript

00:00We've seen how to work with a while,
00:01and I just set up here a really, really basic while,
00:04similar to the one we had before, oh, little typo.
00:08All righty.
00:09Now, we said in the last video that what if we wanted
00:12to actually do, no matter what, our executable code inside
00:17of our while, you want to do it first, only after that start
00:21checking with conditions.
00:23Now, this video is going to be very short,
00:25because the syntax is really, really simple.
00:28Now, instead of setting our do while in the beginning,
00:33we're going to take our while to the end of our loop.
00:37And then we're going to start our application,
00:39start our loop with the word do.
00:42By doing that, our application is going
00:44to run once no matter what.
00:49So even if we set this to be false,
00:52which this is the most explicit way of saying we're never
00:54going to run this again, our application
00:58would run at least one time.
01:00Now, obviously, that's not a really realistic scenario,
01:02but we'd want to run it more than one time.
01:05But that's basically all we really
01:06need to do to set a do while.
01:08And a do while basically means do this no matter what
01:11at least one time, and only after that start
01:14checking our while condition.
01:17And that's really all we really need
01:20to know on the basics of loops.
01:23And all the rest of the videos are
01:24going to be more advanced topics about how
01:27to leverage that knowledge that we have adding into it
01:31a few more things, such as creating loops inside of loops
01:35and adding breaks and some really interesting things
01:39that are more advanced that take us
01:41into a more in-depth world of working with loops.
01:44And we're going to kind of like turn right back and go back
01:47to the for loop, even though we could manipulate all the stuff
01:50we're going to talk about in the next videos
01:53in the do while in the while.
01:54But because the for loop is so convenient and so friendly,
01:57we're just going to go back to it and continue from there.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!