Jumping around to certain spots in script

后端 未结 3 1806
别那么骄傲
别那么骄傲 2021-02-07 16:45

Is there a way to make a script jump to a specific spot like :GOTO in command prompt? I wanted to make the script jump to the beginning when it is ended.

$tag1 =         


        
3条回答
  •  太阳男子
    2021-02-07 17:22

    There's no goto in PowerShell, and nobody misses it :). Just wrap the block of commands in a loop or something.

    Or try the below. You can assign list of commands to a variable, and then execute them with &$varname. It's still not goto, though.

    $commands = {
    
        Write-Host "do some work"
    
        $again = Read-Host "again?"
        if ($again -eq "y"){
            &$commands
        } else {
            Write-Host "end"    
        }
    }
    
    &$commands 
    

提交回复
热议问题