IT Questions and Answers :)

Monday, December 30, 2019

If you are running a loop (While, For, or Foreach) in PowerShell and you want to stop the current iteration and move on to the next one, what statement do you issue?

If you are running a loop (While, For, or Foreach) in PowerShell and you want to stop the current iteration and move on to the next one, what statement do you issue?

  • Next-Item
  • Break
  • Return
  • Continue 

 If you are running a loop (While, For, or Foreach) in PowerShell and you want to stop the current iteration and move on to the next one, what statement do you issue?

EXPLANATION

Understanding the Continue statement

One of the things that is a bit confusing for beginner scripters (and even for some intermediate scripters) is the Continue statement. This is partially because it does not act like it might in some other scripting languages.
Note  Windows PowerShell is not VBScript. Windows PowerShell is not VBScript. Say this 100 times…
So, what does the Continue statement do in Windows PowerShell? It returns flow to the top of the innermost loop that is controlled by a While, For, or Foreach statement. Probably the best way to understand this is to see it in action.
Note  To read more about looping, see these Hey, Scripting Guy! Blog posts.
The following script displays the numbers 1 through 6 as the script works its way through the array.
[array]$a = 1..6
foreach ($i in $a)
{
 $i
}

Share:

0 comments:

Post a Comment

Popular Posts