Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7576535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:56:42+00:00 2026-05-30T16:56:42+00:00

So what the issue is, i have 2 for loops one nested within another.

  • 0

So what the issue is, i have 2 for loops one nested within another. The outer loop calling a procedure, the inner loop setting a attribute for the procedure to use. The problem is that the procedure is that I wan’t to exit the loop use the pos <– attribute call the procedure and re-enter the inner loop. At the minute the pos is only being set once because all the conditions are true within the inner loop meaning that its being replaced each time. I want to be able to set the pos exit the inner loop, call the procedure and re-enter the inner loop and set it pos to a different value? any help would be great!! here is the code

 For Each val As String In vals


        If creditPoints = "20" And semester = "1" And year = "Year 1" Then

            For Each position In MyPosList

                If position.strLabel = "a1" And available(0) <> "False" Then
                    pos = position.strX & " " & position.strY
                    count += 1
                    available(0) = blnavailable
                ElseIf position.strLabel = "b1" And available(1) <> "False" Then
                    pos = position.strX & " " & position.strY
                    count += 1
                    available(1) = blnavailable               
Next
 shortfat(semester, pos, creditPoints, title, year, modStatus, count)
        End If
next
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:56:44+00:00Added an answer on May 30, 2026 at 4:56 pm

    Are you just looking to break out of the inner loop when one of those conditions are met? If so, that’s what the Exit keyword is for. You really should also set a flag to sanity check yourself, too.

    ''//Flag so that we know if we actually found a position
    Dim FoundPosition as Boolean
    For Each val As String In vals
        ''//Reset the flag and assume that are conditions are met
        FoundPosition = False
        If creditPoints = "20" And semester = "1" And year = "Year 1" Then
            For Each position In MyPosList
                If position.strLabel = "a1" And available(0) <> "False" Then
                    pos = position.strX & " " & position.strY
                    count += 1
                    available(0) = blnavailable
                    ''//Flag that our conditions are met
                    FoundPosition = True
                    ''//Exit from the inner loop
                    Exit For
                ElseIf position.strLabel = "b1" And available(1) <> "False" Then
                    pos = position.strX & " " & position.strY
                    count += 1
                    available(1) = blnavailable
                    ''//Flag that our conditions are met
                    FoundPosition = True
                    ''//Exit from the inner loop
                    Exit For
                End If
            Next
            ''//Sanity check to ensure that our conditions are met
            If FoundPosition Then
                shortfat(semester, pos, creditPoints, title, year, modStatus, count)
            Else
                ''//Do something here, either Throw an error or safely handle this case otherwise
            End If
        End If
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that I am calling using EXECUTE IMMEDIATE. The issue
I have an issue with a Loop that doesn't actually loop. I've posted a
I have the same issue as in Excel VBA: Parsed JSON Object Loop but
I have an issue that looks like a race condition with a webview callback
I have an nHibernate query issue that looks quite straight forward, but I can't
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
The issue I have is as follows: My company's supplier gives us an Access
Here's the issue: I have a hook in IE that reacts on WebBrowser.OnNavigateComplete2 event
Here's the issue: I have 2 data contexts that I would like to do
I have a problem and I will try to explain the issue: I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.