Script Center > Scripting Forums > The Official Scripting Guys Forum! > Is there no GOTO in Powershell?
Ask a questionAsk a question
 

AnswerIs there no GOTO in Powershell?

Answers

All Replies

  • Tuesday, November 03, 2009 8:20 PMDavid Wiseman[WiseSoft.co.uk] Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    GOTO statements are normally considered bad practice in modern programming languages - I'm guessing that is why it's not included in PowerShell.  This shouldn't pose much of a limitiation though.
  • Tuesday, November 03, 2009 11:31 PMKarl Mitschke Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    No GOTO

    What is it that you are trying to accomplish?

    Karl
    • Marked As Answer byJoeSchmoe115 Monday, November 16, 2009 3:30 PM
    •  
  • Monday, November 09, 2009 4:39 PMchswin Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Yes it is called a subroutine (kinda)

    Not quite like GOTO but can be used similarly assuming you put your action items into subs in your script.....

    example....
    value1 = "chswin"
    
    if value1 = "chswin" then
        call sub1
    end if
    
    sub sub1
        wscript.echo "chswin"
    end sub
    
    

  • Monday, November 16, 2009 2:55 PMKarl Mitschke Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    chswin;

    The question is about PowerShell, not vbscript :)

    JoeSchmoe115;

    Once again, What is it that you are trying to accomplish?

    Karl
  • Monday, November 16, 2009 3:32 PMJoeSchmoe115 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    chswin;

    The question is about PowerShell, not vbscript :)

    JoeSchmoe115;

    Once again, What is it that you are trying to accomplish?

    Karl

    What I am trying to accomplish is not relevant. All I wanted to know if there was a GOTO in PowerShell. I knew how to work around it ("if" does the job)