If statement for循环中的If语句不在循环中执行

If statement for循环中的If语句不在循环中执行,if-statement,for-loop,powershell-2.0,If Statement,For Loop,Powershell 2.0,我已经试了好几天了,不能理解这里的逻辑。认输 我有一个图像对象,我要把它切成一个10“x8”的网格,网格上有相等的单元格。在第10列之后,它将下降到下一行,并收集随后的10列,以此类推。我似乎无法让它递归到下一行并停留在该行上,相反,它得到一个单元格并返回到第一行 $startColumn = 1 $currentCell = 1 $currentColumn = 1 $currentRow = 1 For($i

我已经试了好几天了,不能理解这里的逻辑。认输

我有一个图像对象,我要把它切成一个10“x8”的网格,网格上有相等的单元格。在第10列之后,它将下降到下一行,并收集随后的10列,以此类推。我似乎无法让它递归到下一行并停留在该行上,相反,它得到一个单元格并返回到第一行

        $startColumn = 1
        $currentCell = 1
        $currentColumn = 1
        $currentRow = 1

        For($i = 1; $i -lt 81; $i++) 
        {
            $startleftCoord = 292
            $starttopCoord = 87
            $startrightCoord = 390
            $startbottomCoord = 162
            $cellheight = 75
            $cellwidth = 98



                if ($firstiterationcomplete -eq 1) {


                 "Changing columns"
                 $startleftCoord = $startleftCoord+($currentColumn*$cellwidth)+(4.05*$currentColumn)
                 $startrightCoord = $startrightCoord+($currentColumn*$cellwidth)+(4.05*$currentColumn)


                    if ($currentColumn -eq 9) {
                        "Changing Rows"                    
                        $currentRow++
                        $currentColumn = $startColumn

                        $startleftCoord = $startleftCoord
                        $startrightCoord = $startrightCoord
                        $starttopCoord = $starttopCoord+($currentRow*$cellheight)+(4.25*$currentRow)
                        $startbottomCoord = $startbottomCoord+($currentRow*$cellheight)+(4.25*$currentRow)
                     }
                }


            "Curent column is " + $currentColumn
            "Row count is " + $currentRow

            #save cellshot
            $cellBounds = [Drawing.Rectangle]::FromLTRB($startleftCoord,$starttopCoord, $startrightCoord, $startbottomCoord)
            $cellObject = New-Object Drawing.Bitmap $cellBounds.Width, $cellBounds.Height
            $cellGraphics = [Drawing.Graphics]::FromImage($cellObject)
            $cellGraphics.CopyFromScreen( $cellBounds.Location, [Drawing.Point]::Empty, $cellBounds.Size)
            $cellGraphics.Dispose()      
            $cellObject.Save($FilePath)

            $currentColumn++
            $currentCell++
            $firstiterationcomplete = 1
            "Saved CELLSHOT to $FilePath."
       }

我已经多次重写了我的IF块。我只是缺少一个简单的解释来解释为什么下面跳过第2列`"


疯狂的标记是怎么回事?你的代码不包含PHP、Python或foreach循环。只是编辑它以包含for循环…我不是专业人士,只是想完成工作。它是powershell。我知道它是powershell。为什么你要将其标记为PHP、Python和foreach?也许他只是想从一些真正的程序员那里获得第二双眼睛。因为这是一种逻辑关于程序循环的问题。我认为它们都适用,但我的想法可能有偏差……请原谅我
Starting to loop image for each ball"


[int]$startCell = 1
[int]$startRow = 1
[int]$startColumn = 1
[int]$totalLoops = 81


[int]$startleftCoord = 293
[int]$starttopCoord = 90
[int]$startrightCoord = 385
[int]$startbottomCoord = 160
[int]$cellheight = 75
[int]$cellwidth = 100



    Do 
    {         


        #get the current time and build the filename from it
        $Time = (Get-Date)

        [string] $FileName += "-cellshot"
        $FileName = "$($Time.Month)"

        $FileName += '-'
        $FileName += "$($Time.Day)" 
        $FileName += '-'
        $FileName += "$($Time.Year)"
        $FileName += '-'
        $FileName += "$($Time.Hour)"
        $FileName += '-'
        $FileName += "$($Time.Minute)"
        $FileName += '-'
        $FileName += "$($Time.Second)"
        $FileName += '-'
        $FileName += "$($Time.Millisecond)"
        $FileName += '-'
        $FileName += [string]$currentCell

        $FileName += '.png'

        #use join-path to add path to filename
        [string] $FilePath = (Join-Path $Path $FileName)



        if (!$currentCell -OR !$currentColumn -OR !$currentRow){
            "Initializing Globals"

            $currentCell = $startCell
            $currentColumn = $startColumn
            $currentRow = $startRow

        }  


       "Designate capture point"

       if ($currentColumn -gt 1 -AND $currentColumn -lt 11) {

            "Calculating side coordinates offset"
            $newleftCoord = $startleftCoord+($currentColumn*$cellwidth)
            $newrightCoord = $startrightCoord+($currentColumn*$cellwidth)

        } elseif ($currentColumn -eq 11) {

            "Resetting column coordinates "
            $currentColumn = $startColumn
            $newleftCoord = $startleftCoord
            $newrightCoord = $startrightCoord

            "Compensating for multiple rows offest"
            $newtopCoord = $starttopCoord+($currentRow*$cellheight)
            $newbottomCoord = $startbottomCoord+($currentRow*$cellheight)
            $currentRow++


        }else{
           "Getting number one"
            $newleftCoord = $startleftCoord
            $newtopCoord = $starttopCoord
            $newrightCoord = $startrightCoord
            $newbottomCoord = $startbottomCoord
        }



        "Current Column is " + $currentColumn
        "Current row is " + $currentRow
        "Current cell is " + $currentCell


        #save cellshot
        $cellBounds = [Drawing.Rectangle]::FromLTRB($newleftCoord,$newtopCoord, $newrightCoord, $newbottomCoord)
        $cellObject = New-Object Drawing.Bitmap $cellBounds.Width, $cellBounds.Height
        $cellGraphics = [Drawing.Graphics]::FromImage($cellObject)
        $cellGraphics.CopyFromScreen( $cellBounds.Location, [Drawing.Point]::Empty, $cellBounds.Size)
        $cellGraphics.Dispose()      
        $cellObject.Save($FilePath)





        $currentColumn++
        $currentCell++


    }Until ($currentCell -eq $totalLoops)
Start-Sleep -Second 20
}




        #load required assembly
        Add-Type -Assembly System.Windows.Forms   

        Start-Sleep -Seconds 5       

        $ballarray = @{}

        Do {



            #run screenshot function
           # If ($ballarray.count -eq 20){
           #    GenScreenshot
           #     "Snapped screenshot - $Filename ."
           # }else{
                Do{

                GetNewBall
                }Until($currentCell -eq 80)
            #}


            #$bounds = [Drawing.Rectangle]::FromLTRB(307,129, 1060, 668)
            #screenshot $bounds $Filepath

            #Start-Sleep -Second 10
        }Until($ballarray.count -eq 20)`