Sign in Join
Wiki copytemporary

In: what changed

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

Title: In

OldNewLine
1+The [[Reserved word|reserved word]] `in`:
2+
3+- It tests whether a value is in a [[Set|set]]. It returns the [[Boolean|boolean]] value \[\[True\|
4+
5+`true`\]\] if the value belongs to the set and [[False|false]] if the value does not belong to the set.
6+
7+- It is also used with the reserved word [[For|for]] in [[for-in loop]].
8+- It is also usable in [[Uses|uses‑clauses]].
9+
10+## Example \#1
11+
12+``` pascal
13+program projectin;
14+uses SysUtils, TypInfo;
15+type
16+ Berry = (Blueberry, FlyHoneysuckle, Lingonberry, Raspberry, Snowberry, Strawberry);
17+ Berries = set of berry;
18+var
19+ basket: Berries;
20+ someberry: berry;
21+ str: string;
22+ i: integer;
23+begin
24+ basket := [];
25+ writeLn('Choose a berry from the following berries into your basket');
26+ repeat
27+ i := 1;
28+ for someberry in berry do
29+ begin
30+ Str := GetEnumName(TypeInfo(Berry),ord(someberry));
31+ writeln(i,' : ',Str);
32+ inc(i);
33+ end;
34+ writeln('0 : exit');
35+ writeln;
36+ readln(i);
37+ if i>0 then
38+ begin
39+ someberry :=Berry(i-1);
40+ Include(basket, someberry);
41+ end;
42+ until i=0;
43+ if (FlyHoneysuckle in basket) or (Snowberry in basket) then
44+ begin
45+ writeln('You have poisonous berries in your basket');
46+ if FlyHoneysuckle in basket then
47+ writeln('Your basket has a poisonous Fly honeysuckle!') ;
48+ if Snowberry in basket then
49+ writeln('Your basket has a poisonous Snowberry!');
50+ end;
51+ writeln('So you had these berries in your basket:');
52+ for someberry in basket do
53+ begin
54+ Str := GetEnumName(TypeInfo(Berry), Ord(someberry));
55+ writeln(Str);
56+ end;
57+ readln;
58+end.
59+```
60+
61+## Example \#2
62+
63+``` pascal
64+const Test: char = 'q';
65+
66+begin
67+ if (Test in ['0'..'9']) then
68+ Writeln('Digit')
69+ else if (Test in ['A'..'z']) then
70+ Writeln('Letter')
71+ else
72+ Writeln('Other');
73+end.
74+```
75+
76+---
77+*From the Free Pascal wiki, page "In", as it stood on 2022-05-26 after a change by Trev, 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