Loops 如何在PowerShell中设置循环变量的约束?
我有以下代码:Loops 如何在PowerShell中设置循环变量的约束?,loops,powershell,conditional-statements,Loops,Powershell,Conditional Statements,我有以下代码: $SE = 215 function F { Param ($OE) For ($iteration = 1; $iteration -le 100; $iteration++) { Write-host "Iteration" $iteration $result = $OE - 1 $OE = $result $result ForEach ($input in $re
$SE = 215
function F
{
Param ($OE)
For ($iteration = 1; $iteration -le 100; $iteration++)
{
Write-host "Iteration" $iteration
$result = $OE - 1
$OE = $result
$result
ForEach ($input in $result)
{
$OPT = 5 * [double]$Steel.Force * 1000 * ([math]::pow([double]$Steel.L, 4))/(384 * $input * ([math]::pow(10, 9)) * [double]$Steel.I * ([math]::pow(10, -8)))
$OPT
}
}
}
F -OE $SE
我想为两个变量设置约束:
$result
和$OPT
。例如,当$result-le 205
和/或$OPT-ge 5
时,迭代将停止。目前,迭代将一直运行,直到$iteration=100
。我试图添加一个do{}While()
循环,但没有成功。有时脚本被卡住了。有什么想法吗 您可以使用break
退出循环
例如:
if ($result -le 205 -and $OPT -ge 5) { break }
您可以在此处阅读更多信息:
您可以使用
break
退出循环
例如:
if ($result -le 205 -and $OPT -ge 5) { break }
您可以在此处阅读更多信息:
如果我将此代码放在
ForEach循环之后。实际上,只有当
$OPT-ge 5`时,它才能断开。但我会做一些进一步的研究。谢谢。如果我把这个代码放在ForEach循环之后。实际上,只有当
$OPT-ge 5`时,它才能断开。但我会做一些进一步的研究。非常感谢。