Powershell goto statement replacement -
i know powershell doesnt have goto statements. have requirement follows:
foreach($x in $xyz) { #something works fine if($a -eq $b) { #something works fine if($c -eq $d) { $c | add-content "path\text.txt" }else { #here need go first if statement, rather going foreach loop } }else { #nothing } }
have tried break :---- , functions both doesnt seems work in case. when use break :----, notifies error in last else. when try use function below:
foreach($x in $xyz) { #something works fine function xyz { if($a -eq $b) { #something works fine if($c -eq $d) { $c | add-content "path\text.txt" }else { xyz } }else { #nothing } } }
it not entering function xyz.
any other suggestions achieve this.? appreciated.
i think want nested loops:
foreach ($item in $data) { while (condition $data) { # stuff, calculate $state if (othercondition($state)) { # without label exit in inner loop only, # execution continue @ point-x. break; } # more stuff } # point-x }
Comments
Post a Comment