Creating a subloop

Tagged: 

This topic contains 3 replies, has 4 voices, and was last updated by  Richard Siddaway 3 weeks, 6 days ago.

  • Author
    Posts
  • #75523

    Hil
    Participant

    Hi , Instead of placing all my code in the main loop, I wanted to create a SUBLOOP . Then call the subloop from the main loop.
    For example in Winbatch, I could call a subloop with "GoSub" and use the "Return" statement to return back to the main loop.
    How would I do something similar in Powershell?

    Thanks
    Hil

  • #75524

    iain Barnetson
    Participant

    I use foreach within a foreach.
    Is that what you're looking for ?

  • #75526

    Ben Camareno
    Participant

    You're probably looking for:

    Do {} until ($something -eq "something")

    But without a sample code, is a bit hard to determine your scenario.

  • #75610

    Richard Siddaway
    Moderator

    The nearest thing to your description is to create a function and call that. I'd suggest very strongly that you take the time to investigate how PowerShell works – if you just port over the way you do things in other languages you can end up with very inefficient code

You must be logged in to reply to this topic.