Question How do I pause my for loop until variable "Ready" = True ?

htconex

Member
Joined
May 16, 2012
Messages
7
Programming Experience
5-10
How do I pause my for loop until variable "Ready" = True ?

For i = 0 To StudentList.Items.Count - 1
Msgbox(StudentList.Items(i))
Next
 
You should use a while loop because this is not possible (to my knowledge) in a for loop:

VB.NET:
Dim i as integer = 0
While i < StudentList.Items.Count - 1
   If Ready = True Then
      i += 1
   Else
      'do nothing
   End If
End While

Be careful because you could get stuck in an infinite loop if ready never gets set, but you could avoid this by using a try block and catching an arithmatic overflow exception which would eventually occur in i.
 
Please describe what you're actually trying to accomplish rather than how you're trying to accomplish it because "pausing a loop" is not something that you would ever do. ss7thirty's suggestion is definitely not something you should do. That is known as a "busy waiting" loop and it is something that should never be done.
 

Latest posts

Back
Top