Skip to content

Commit

Permalink
Fixes #3709 - rewrite about_Continue for clarity (#4284)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbytreed authored and sdwheeler committed May 9, 2019
1 parent 53604b2 commit c14d932
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 34 deletions.
37 changes: 29 additions & 8 deletions reference/3.0/Microsoft.PowerShell.Core/About/about_Continue.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
ms.date: 06/25/2017
---
ms.date: 5/9/2019
schema: 2.0.0
keywords: powershell,cmdlet
title: about_Continue
Expand All @@ -22,30 +22,51 @@ statement in a script. For information about labels, see
[about_Break](about_Break.md).

In the following example, program flow returns to the top of the While loop
if the $ctr variable is equal to 5. As a result, all the numbers between 1
if the `$ctr` variable is equal to 5. As a result, all the numbers between 1
and 10 are displayed except for 5:

```powershell
while ($ctr -lt 10)
{
$ctr += 1
if ($ctr -eq 5) {Continue}
if ($ctr -eq 5)
{
Continue
}
Write-Host -Object $ctr
}
```

Note that in a `For` loop, execution continues at the first line in the
loop. If the arguments of the `For` statement test a value that is modified
by the `For` statement, an infinite loop may result.
When using a `For` loop, execution continues at the `<Repeat>` statement,
followed by the `<Condition>` test. In the example below, an infinite loop
will not occur because the decrement of `$i` occurs after the `Continue`
keyword.

```powershell
# <Init> <Condition> <Repeat>
for ($i = 0; $i -lt 10; $i++)
{
Write-Host -Object $i
if ($i -eq 5)
{
continue
# Will not result in an infinite loop.
$i--;
}
}
```

## SEE ALSO

[about_Break](about_Break.md)

[about_For](about_For.md)

[about_Comparison_Operators](about_Comparison_Operators.md)

[about_Throw](about_Throw.md)

[about_Trap](about_Trap.md)

[about_Try_Catch_Finally](about_Try_Catch_Finally.md)
[about_Try_Catch_Finally](about_Try_Catch_Finally.md)
33 changes: 27 additions & 6 deletions reference/4.0/Microsoft.PowerShell.Core/About/about_Continue.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
ms.date: 06/25/2017
ms.date: 5/9/2019
schema: 2.0.0
keywords: powershell,cmdlet
title: about_Continue
Expand All @@ -23,26 +23,47 @@ statement in a script. For information about labels, see
[about_Break](about_Break.md).

In the following example, program flow returns to the top of the While loop
if the $ctr variable is equal to 5. As a result, all the numbers between 1
if the `$ctr` variable is equal to 5. As a result, all the numbers between 1
and 10 are displayed except for 5:

```powershell
while ($ctr -lt 10)
{
$ctr += 1
if ($ctr -eq 5) {Continue}
if ($ctr -eq 5)
{
Continue
}
Write-Host -Object $ctr
}
```

Note that in a `For` loop, execution continues at the first line in the
loop. If the arguments of the `For` statement test a value that is modified
by the `For` statement, an infinite loop may result.
When using a `For` loop, execution continues at the `<Repeat>` statement,
followed by the `<Condition>` test. In the example below, an infinite loop
will not occur because the decrement of `$i` occurs after the `Continue`
keyword.

```powershell
# <Init> <Condition> <Repeat>
for ($i = 0; $i -lt 10; $i++)
{
Write-Host -Object $i
if ($i -eq 5)
{
continue
# Will not result in an infinite loop.
$i--;
}
}
```

## SEE ALSO

[about_Break](about_Break.md)

[about_For](about_For.md)

[about_Comparison_Operators](about_Comparison_Operators.md)

[about_Throw](about_Throw.md)
Expand Down
34 changes: 27 additions & 7 deletions reference/5.0/Microsoft.PowerShell.Core/About/about_Continue.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
ms.date: 06/25/2017
ms.date: 5/9/2019
schema: 2.0.0
keywords: powershell,cmdlet
title: about_Continue
---

# About Continue

## SHORT DESCRIPTION
Expand All @@ -23,26 +22,47 @@ statement in a script. For information about labels, see
[about_Break](about_Break.md).

In the following example, program flow returns to the top of the While loop
if the $ctr variable is equal to 5. As a result, all the numbers between 1
if the `$ctr` variable is equal to 5. As a result, all the numbers between 1
and 10 are displayed except for 5:

```powershell
while ($ctr -lt 10)
{
$ctr += 1
if ($ctr -eq 5) {Continue}
if ($ctr -eq 5)
{
Continue
}
Write-Host -Object $ctr
}
```

Note that in a `For` loop, execution continues at the first line in the
loop. If the arguments of the `For` statement test a value that is modified
by the `For` statement, an infinite loop may result.
When using a `For` loop, execution continues at the `<Repeat>` statement,
followed by the `<Condition>` test. In the example below, an infinite loop
will not occur because the decrement of `$i` occurs after the `Continue`
keyword.

```powershell
# <Init> <Condition> <Repeat>
for ($i = 0; $i -lt 10; $i++)
{
Write-Host -Object $i
if ($i -eq 5)
{
continue
# Will not result in an infinite loop.
$i--;
}
}
```

## SEE ALSO

[about_Break](about_Break.md)

[about_For](about_For.md)

[about_Comparison_Operators](about_Comparison_Operators.md)

[about_Throw](about_Throw.md)
Expand Down
34 changes: 27 additions & 7 deletions reference/5.1/Microsoft.PowerShell.Core/About/about_Continue.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
ms.date: 06/25/2017
ms.date: 5/9/2019
schema: 2.0.0
keywords: powershell,cmdlet
title: about_Continue
---

# About Continue

## SHORT DESCRIPTION
Expand All @@ -23,26 +22,47 @@ statement in a script. For information about labels, see
[about_Break](about_Break.md).

In the following example, program flow returns to the top of the While loop
if the $ctr variable is equal to 5. As a result, all the numbers between 1
if the `$ctr` variable is equal to 5. As a result, all the numbers between 1
and 10 are displayed except for 5:

```powershell
while ($ctr -lt 10)
{
$ctr += 1
if ($ctr -eq 5) {Continue}
if ($ctr -eq 5)
{
Continue
}
Write-Host -Object $ctr
}
```

Note that in a `For` loop, execution continues at the first line in the
loop. If the arguments of the `For` statement test a value that is modified
by the `For` statement, an infinite loop may result.
When using a `For` loop, execution continues at the `<Repeat>` statement,
followed by the `<Condition>` test. In the example below, an infinite loop
will not occur because the decrement of `$i` occurs after the `Continue`
keyword.

```powershell
# <Init> <Condition> <Repeat>
for ($i = 0; $i -lt 10; $i++)
{
Write-Host -Object $i
if ($i -eq 5)
{
continue
# Will not result in an infinite loop.
$i--;
}
}
```

## SEE ALSO

[about_Break](about_Break.md)

[about_For](about_For.md)

[about_Comparison_Operators](about_Comparison_Operators.md)

[about_Throw](about_Throw.md)
Expand Down
34 changes: 28 additions & 6 deletions reference/6/Microsoft.PowerShell.Core/About/about_Continue.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
---
ms.date: 06/25/2017
ms.date: 5/9/2019
schema: 2.0.0
keywords: powershell,cmdlet
title: about_Continue
---
# About Continue

## SHORT DESCRIPTION

Describes how the `Continue` statement immediately returns the program flow
to the top of a program loop.

Expand All @@ -21,26 +22,47 @@ statement in a script. For information about labels, see
[about_Break](about_Break.md).

In the following example, program flow returns to the top of the While loop
if the $ctr variable is equal to 5. As a result, all the numbers between 1
if the `$ctr` variable is equal to 5. As a result, all the numbers between 1
and 10 are displayed except for 5:

```powershell
while ($ctr -lt 10)
{
$ctr += 1
if ($ctr -eq 5) {Continue}
if ($ctr -eq 5)
{
Continue
}
Write-Host -Object $ctr
}
```

Note that in a `For` loop, execution continues at the first line in the
loop. If the arguments of the `For` statement test a value that is modified
by the `For` statement, an infinite loop may result.
When using a `For` loop, execution continues at the `<Repeat>` statement,
followed by the `<Condition>` test. In the example below, an infinite loop
will not occur because the decrement of `$i` occurs after the `Continue`
keyword.

```powershell
# <Init> <Condition> <Repeat>
for ($i = 0; $i -lt 10; $i++)
{
Write-Host -Object $i
if ($i -eq 5)
{
continue
# Will not result in an infinite loop.
$i--;
}
}
```

## SEE ALSO

[about_Break](about_Break.md)

[about_For](about_For.md)

[about_Comparison_Operators](about_Comparison_Operators.md)

[about_Throw](about_Throw.md)
Expand Down

0 comments on commit c14d932

Please sign in to comment.