In/fi
Varattu sana in testaa kuuloko kyseinen arvo joukkoon. Se palauttaa boolean arvon true jos arvo kuuluu joukkoon ja arvon false jos se ei kuulu kyseiseen joukkoon. In sanaa käytetään myös varatun sanan for kanssa for-in -silmukassa.
Esimerkki ohjelma
program projectin;
uses SysUtils,TypInfo;
type
marja = (mustikka, lehtokuusama, puolukka, vadelma, lumimarja, mansikka);
Berries = set of marja;
var
kori: Berries;
someberry:marja;
str:string;
i:integer;
begin
kori := [];
writeLn('Valitse jokin marja seuraavista marjoista koriin');
repeat
i:=1;
for someberry in marja do
begin
Str := GetEnumName(TypeInfo(marja),ord(someberry));
writeln(i,' : ',Str);
inc(i);
end;
writeln('0 : poistu ');
writeln;
readln (i);
if i>0 then
begin
someberry :=marja(i-1);
Include(kori,someberry);
end;
until i=0;
if (lehtokuusama in kori) or (lumimarja in kori) then
begin
writeln ('Sinulla on myrkyllisiä marjoja korissasi');
if lehtokuusama in kori then
writeln ('Korissasi on myrkyllinen lehtokuusama!') ;
if lumimarja in kori then
writeln ('Korissasi on myrkyllinen lumimarja!');
end;
writeln('Joten sinulla oli nämä marjat korissasi:');
for someberry in kori do
begin
Str := GetEnumName(TypeInfo(marja),ord(someberry));
writeln(Str);
end;
readln ;
end.From the Free Pascal wiki, page "In/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.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
