From the course: Visual Basic Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Use For loop to run code a specific number of times

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

From the course: Visual Basic Essential Training

Start my 1-month free trial

Use For loop 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 lists chapter. Use the for loop when you know how many times you must repeat the code. To add one, type in the word for, then press the Tab key twice and you'll get this code snippet and you can move between the index one and 10 by pressing the Tab key. I'll press the Escape key 'cause I don't want to use that at the moment. The way you read line seven is we're going to loop 10 times. This index is useful within the body of my for loop, so you give it the name that makes sense for your code and then you specify the starting value, one, and the ending value of 10. Then the code goes between the for and the next keyword. Let's output this to the screen like that. What do you expect to see when I click on the For Loop? Yes, you…

Contents