Results 1 to 5 of 5

Thread: A Basic question about for loops

  1. #1

    Thread Starter
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169

    Talking

    If I have a for loop with a function in it

    For i = 0 to ubound(myarray)
    'code
    next

    does vb have to call the function every time it loops, or does it store the value of the call in memory?

    Thanks.
    That which does not kill us, only makes us stronger.

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    will call it everytime. same with any other loop.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    Lively Member xhomerx's Avatar
    Join Date
    Feb 2001
    Posts
    98
    It calls it everytime which gives u the ability to send a diff value to the function everytime (As shown below) - If the value of your function isnt going to change call it before your loop

    For i = 0 to ubound(myarray)
    Call FunctionName(i)
    next

  4. #4

    Thread Starter
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169

    Talking

    Thats what I thought, but the debugger never goes to that line once it enters the loop, so that made me begin to question it.

    Thanks!!!
    That which does not kill us, only makes us stronger.

  5. #5
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    If you want to save some time
    code with a stored variable

    Code:
    Dim ub As Integer
    
    ub =  UBound(myarray) 
    
    For I = 0 To ub
    Call FunctionName(I) 
    Next
    
    'Code improved by vBulletin Tool (Save as...)
    Last edited by Evan; Mar 7th, 2001 at 12:39 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width