PARTS:
Part 20
Part 21
Part 22
Part 23
Part 24
Part 25
Part 26
}
The following code snippet is a For loop that counts from 1 to 100:
For($i=1;$i -lt 101;$i++) {
write-host $i
}
The section is executed only once for the For loop and is used for initialization.
In this example, I used this section to initialize $i to the value of 1. The
section defines what condition must be true before the code in the code block gets executed.
In this example, I state that if $i is less than 101, it can execute the code. The section
is code that is executed each time the loop executes. In this case, I increment $i by 1 by
using the shorthand notation of $i++, which is functionally equivalent to $i = $i + 1. Finally,
for each iteration of the loop, I output the value of $i. This effectively makes the script count
from 1 to 100 since once $i is incremented to the value of 101, the condition that $i is less
than 101 is no longer true and the loop stops executing.
NOTE If you have a programming background or have used C, C++, or Java, the ++ operator
should be nothing new to you.
Pages:
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478