Content Archived

This content is no longer current. Our recommendation for up to date content: http://channel9.msdn.com/Series/Visual-Basic-Fundamentals-for-Absolute-Beginners

For . . . Next Iterations - 08

Sign in to queue

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
    johnel

    @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