Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7739617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:34:04+00:00 2026-06-01T08:34:04+00:00

I have the following PowerShell loop: Set-Variable -Name YELLOW -Option ReadOnly -Value 0 Set-Variable

  • 0

I have the following PowerShell loop:

Set-Variable -Name YELLOW -Option ReadOnly -Value 0
Set-Variable -Name ORANGE -Option ReadOnly -Value 1
Set-Variable -Name RED    -Option ReadOnly -Value 2

While ($true) {
    for ($color = $YELLOW; $color -le $RED; $color++) { 
        $LastWriteTime = ((Get-Item $FilePath).LastWriteTime)
        $waitTime = (Get-Date).AddMinutes(-($WarningTimeArray[$color]))
        $SleepTime = ($LastWriteTime - $waitTime).TotalSeconds
        If ($SleepTime -gt 0) {
            $WarningFlagArray[$color] = $false;
            SendMail ("Start-Sleep -Seconds" + $SleepTime)
            Start-Sleep -Seconds $SleepTime
            Continue  #Actually want a "redo"
        }
        ElseIf (-not $WarningFlagArray[$color]) {   
            SendMail $WarningMessageArray[$color]
           $WarningFlagArray[$color] = $true
        }
    }
}

When PowerShell hits the “Continue”, it continues back to the top of the for loop, and goes to the next color.

In Perl, you have last (equivalent to PowerShell’s break) and you have next (equivalent to PowerShell’s continue). You also have the redo which goes back to the top of the loop, but doesn’t increment the for loop counter.

Is there an equivalent Powershell command to Perl’s redo function for the for loop?

I can easily convert the statement into a while loop to get around this particular issue, but I was wondering if there is something like redo anyway.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:34:06+00:00Added an answer on June 1, 2026 at 8:34 am

    I’m pretty sure PowerShell doesn’t support what you’re looking for. You can have labelled break and continue statements but neither will take you to the top of the inside of the associated loop/switch construct. If PowerShell had a goto statment you’d be set but I’m glad it doesn’t have that keyword. 🙂 For more info on labelled break/continue see the about_break help topic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following xml: <?xml version=1.0 encoding=UTF-8?> <sections> <section name=Options> <item key=HLVersionControlWebServiceURL value=http://www.personec.no/webservices/HLVersionControl/HLVersionControl.asmx
In Powershell, suppose I have the following xml: <Users> <User Name=Foo> <Friends> <Friend Name=Bar/>
I have the following script set as my VS2010 pre-build script: cd $(ProjectDir) C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe
I have the following string expression in a PowerShell script: select count(*) cnt from
I have the following log entry that I am processing in PowerShell I'm trying
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have the following PowerShell code: function Get-SmoConnection { param ([string] $serverName = ,
I have the following code snippet from my PowerShell script that... Loops through a
I have the following PowerShell script that will parse some very large file for
I have the following code to connect to my office 365 account using powershell:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.