aAbEBBBAX-~| 9466VBC~~BW~B G75646464VC~C-~ G764V 75F 75Z 4G79VYB-~X

While.` In our solar system, planets orbit the sun. We follow these paths in the night sky. We discover repetition here—like a while-loop.`In our programs,` a while-loop continues forever—until its expression is false. Some loops do not progress through a simple range of numbers. While is good here.`An example.` This program shows a while-loop. The while-keyword is followed by an expression. This expression must evaluate to a boolean value (true or false). `True: `The expression is evaluated each time the loop is encountered. If the result is true, the loop body statements are executed.`Notes, above program.` The conditional expression in the while-loop is contained in parentheses. It is equivalent to what we might place in an if-statement. `If `if`This loop will be entered only if the condition i < 10 evaluates to true. A while-loop may never be entered.`Statements: `The loop body statements are then executed. Before it executes again, the condition i < 10 is evaluated.`Boolean: `The boolean result is checked. We must be careful with while-loops that use conditions that prevent execution of the loop body.`Bool `bool`While true.` We can use "true" in the expression of a while-loop. This program uses a while-true loop. An empty while-loop with this condition is by definition an infinite loop. `You can use while(true) loops to great effect if you carefully provide exit conditions in the loop body statements.`Style: `The while(true) loop is sometimes a clearer and more self-documenting loop style than other more popular styles.`True `true`While true, notes.` This program would loop infinitely if the while conditions were not correct or the variable were not incremented properly. `Studies show that junior programmers understand the intent of while(true) loops better than other loops.`Sentence: `This is probably because they can be read like a spoken sentence and the exit conditions are more clearly documented.`You can read more descriptions of studies such as this one in the book Code Complete by Steve McConnell.`Variable assignment.` Here we assign a variable in a while-loop's expression. We can alias a variable for use in the loop body. This is useful if the expression is slow or complex. `Performance: `We can sometimes eliminate duplicate evaluations of the expression and improve performance.`Implicitly convert type error.` The condition of a while-loop must evaluate to true or false. In C# an int never evaluates to true or false—we must use an equality test. `Do While.` This is a less common loop in C#. It is an inverted version of the while-loop. It executes the loop statements unconditionally the first time. `Do-While `do`Jump statements.` In the C# language we can use break, return and goto to change control flow in a while-loop. We can think of control flow (how statements are encountered) like a river. `Break `break`Return `return`Goto `goto`Research.` There is simple rule that you can use to tell if you should use a while-loop. If you don't know the total number of iterations, a while-loop is often the best choice. `Quote: `If you don't know ahead of time exactly how many times you'll want the loop to iterate, use a while-loop (Code Complete).`A summary.` A while-loop continues until its condition expression is false. A data source can be polled. A timer can be checked. A result can be queried.`Less-common applications` of the while-loop include the while(true) loop style. A while-loop can make looping logic easier to reason about. This is a huge benefit.

OHDUFDDHDHQHbHJHAD{DOH%O{FDOOH{ContinueHpHR-loop until index is equalHj10.DOOFHiiHy0;DOOFHRF (i < 10)DOO{DOOOH5.Ha(FUWhile statement UF);FDOOOH{Ha the indexHjthe screen.DOOOFH'i);FDOOOH{Increment the variable.DOOOFi++;DOO}DO}D}DDFDDWhile statement 0DWhile statement 1DWhile statement 2DWhile statement 3DWhile statement 4DWhile statement 5DWhile statement 6DWhile statement 7DWhile statement 8DWhile statement 9FDDHDHQHbHJHAD{DOH%O{DOOHiindexHy0;FDOOH{Continue looping infinitely until Hzernal condition is met.DOOFHRF (FtrueF)DOO{DOOOHiHhHy++index;FDOOOH{CheckHjsee if limit is hit.DOOOFHmHh > 5)DOOO{DOOOOH'FUWhile-loop breakUF);DOOOOHGDOOO}FDOOOH{You can add another condition.DOOOFHmHh > 100)DOOO{DOOOOthrow HqH+(FUNever hitUF);DOOO}FDOOOH{HaHjthe screen on each iteration.DOOOFH'FUWhile-loop statementUF);DOO}DO}D}DDFDDWhile-loop statementDWhile-loop statementDWhile-loop statementDWhile-loop statementDWhile-loop statementDWhile-loop breakFDDHDHQHbHJHAD{DOH%O{DOOHiHhHy4;DOOHii;FDOOH{You can assign a variableHpthe HR-loop condition statement.DOOFHRF ((iHyHh) >= 0)DOO{FDOOOH{In the HR-loop body, both iHVHh are equal.DOOOFH'FUWhile {0} {1}UF, i, Hh);DOOOHh--;DOO}DO}D}DDFDDWhile 4 4DWhile 3 3DWhile 2 2DWhile 1 1DWhile 0 0FDDHJHAD{DOH%O{DOOHiHEHy10;DOOFHRF (FHEF)DOO{DOO}DO}D}DDFResultsFDDError CS0029DCannot implicitly cHN type 'Hz'Hj'bool'DDFDDHJHAD{DOH%O{DOOHiHEHy10;DOOFHRF (FHE > 0F)DOO{DOOOHE--;DOO}DO}D}FDDHDHQHbHJHAD{DOH%O{DOOHiHEHyF0F;FDOOH{Begin do-HR loop.DOOH9Terminates when HE equals 2.DOOFdoFDOO{DOOOH'HE);FDOOOH{Add oneHjHE.DOOOFHE++;DOO} FHRF (HE <= 2);DO}D}DDFDD0D1D2F

&ibC9,Ywhile-loop with conditiontrue in while-loopassigns variable in while conditioncauses convert type erroravoids errordo, while