Creating a subloop

This topic contains 3 replies, has 4 voices, and was last updated by  Richard Siddaway 8 months ago.

  • Author
  • #75523


    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?


  • #75524

    iain Barnetson

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

  • #75526

    Ben Camareno

    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

    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.