-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestfile.ps1
More file actions
58 lines (51 loc) · 1.35 KB
/
testfile.ps1
File metadata and controls
58 lines (51 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# For Each Loop in PowerShell
# $Websites = 'Google.com', 'Microsoft.com', 'bullettrain.jp'
# foreach ($site in $Websites) {
# ping $site
# }
#Do Until Loop in PowerShell
# $number = [int]1026
# do {
# $guess = [int](Read-Host -Prompt "Enter your guess?")
# if ($guess -lt $number) {
# Write-Output "Too low"
# } elseif ($guess -gt $number) {
# Write-Output "Too high"
# }
# }
# until ($guess -eq $number) {
# Write-Output "Congratulations! You guessed the correct number: $number"
# }
#Do While Loop in PowerShell
# $number = [int]1026
# do {
# $guess = [int](Read-Host -Prompt "Enter your guess?")
# if ($guess -lt $number) {
# Write-Output "Too low"
# } elseif ($guess -gt $number) {
# Write-Output "Too high"
# }
# }
# while ($guess -ne $number) {
# Write-Output "Congratulations! You guessed the correct number: $number"
# }
# Break, Continue, and Return in PowerShell
for ($i = 1; $i -le 5; $i++) {
Write-Output "Sleeping for $i seconds"
Start-Sleep -Seconds $i
break
}
while ($i -lt 5) {
$i++
if ($i -eq 3) {
continue
}
Write-Output "while with continue: $i"
}
$number = 1..10
foreach ($n in $number) {
if ($num -ge 4) {
return $n # exit out of the loop and pass the value of $n to the caller
}
Write-Output "foreach with return: $n"
}