From the course: Visual Basic Essential Training

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Use For loops to run code a specific number of times

Use For loops to run code a specific number of times - Visual Basic Tutorial

From the course: Visual Basic Essential Training

Use For loops to run code a specific number of times

- [Instructor] Visual Basic has several ways to repeat a section of code. In this chapter, we'll explore the for loop and the do loop. We'll look at the for-each loop in the arrays and list chapter. Use the for loop when you know how many times you must repeat the code. To add one, type in for and then press the Tab key twice. Visual Studio will enter this code for you. This is a snippet and it has some placeholders. They're in yellow. So if I press the Tab key, it'll move between the placeholders. This allows me to change the name of the variable that's associated with this For Next and the starting value and the ending value. I don't want to do that, so I'll press the escape key, which dismisses the placeholders. Now I can use the index value within the body of my For Next. So what I'm going to do first is grab this and paste it in here. So what this code does is it goes to the parent window. There's a method on the parent window called ShowIt. And then it's going to output the…

Contents