Sign in Join
Wiki copytemporary

While/fi: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: While/fi

OldNewLine
1+`while` **ehto-lauseke** [[Do/fi|do]] **suoritettava lauseke** (tai lohko). Tämän luupin yhteydessä toistetaan lauseketta niin kauan kuin ehdon arvo on [[True/fi|true]]. Ehto-lauseke arvioidaan ennen kutakin iterointia, määritetään, suoritetaanko seuraava [[Block|lohko]] (tai yksittäinen lauseke). Tämä on tärkein ero [[Repeat|repeat … until-silmukkaan]], jossa lohko suoritetaan joka tapauksessa, mutta seuraavat iteraatiot eivät välttämättä tapahdu.
2+
3+Seuraava esimerkki sisältää saavuttamattoman koodin:
4+
5+``` pascal
6+program whileFalse(input, output, stderr);
7+
8+begin
9+ while false do
10+ begin
11+ writeLn('Tätä ei koskaan tulosteta');
12+ end;
13+end.
14+```
15+
16+Yleensä käytetään `while`-silmukoita, missä, toisin kuin [[For|for-silmukassa]], juoksevaa indeksi [[Variable|muuttujaa]] ei tarvita, suoritettua lohkoa ei voida päätellä indeksistä, jota on lisätty yhdellä tai vältetään [[Break|break-lausetta]] (joka yleensä ilmaisee huonoa ohjelmointityyliä).
17+
18+``` pascal
19+program whileDemo(input, output, stderr);
20+
21+var
22+ x: integer;
23+begin
24+ x := 1;
25+
26+ // prints non-negative integer powers of two
27+ while x < high(x) div 2 do
28+ begin
29+ writeLn(x);
30+ inc(x, x); // x := x + x
31+ end;
32+end.
33+```
34+
35+## Katso myös
36+
37+- [[Infinite loop/fi|Ikuinen silmukka]]
38+
39+---
40+*From the Free Pascal wiki, page "While/fi", as it stood on 2022-08-06 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history