Content Archived

This content is no longer current. Our recommendation for up to date content:

For . . . Next Iterations - 08

Play For . . . Next Iterations - 08
Sign in to queue


Iterations allow our applications to loop through a block of code until a condition is satisfied. We'll cover several different types of iteration statements throughout this series, but we'll start with the for iteration statement. I'll demonstrate how to utilize "code snippets" to help remind you of the syntax for this complex statement, and will demonstrate debugging in action as we watch the values of our loops displayed in the Visual Studio IDE in several ways.

Download the source code For...Next Iterations



The Discussion

  • User profile image
    halit ates

    First, I didn't understand 'for statement' covers which area.
    Moreover, In the first example 'exit for' is located inside if statement, how is the operation queue?

    Does it mean "never exit from 'for statement' unless 'if statement' is validated"?
    Should we follow statements line by line or when a statement begins it ends with an end point declaration?

  • User profile image
    halit ates

    Sorry, I think I had found the answer about 'exit for' by making a simple test.
    It simply disrupts for statement and code continues from the line after 'next', and 'exit for' isn't also a must for such a statement, boundaries are defined with for statement anyway.

  • User profile image

    @halit ates:The "Exit For" statement jumps the code out of the "For Next" statement. Say that you need to evaluate whether a condition is true for thousands of values (For index = 1 to 1000000)  . If the value you are looking for is the first one that is evaluated and is true then without the "Exit For" statement your code would check the next 999999 values even though you have already found the value that you are looking for.  So basically the "Exit For" simply speeds up the execution of your software by "jumping over" all of the values that you do not need to evaluate. In older versions of basic you would have used a "GoTo" statement to do the same thing at the expense of adding one more line of code.

Add Your 2 Cents