Autor Beitrag
gorrila
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Sa 02.02.08 15:57 
Wie kann ich bei einer if-Anweisung checken lassen ob die zahl zwischen 2 grenzen liegt ?
if wert = 0...30 then ... war mein ansatz, das haut aber nicht hin
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Sa 02.02.08 15:58 
ausblenden Delphi-Quelltext
1:
2:
if (a >= 5) and (a <= 30) then
  dosomething;

Edit: oder:
ausblenden Delphi-Quelltext
1:
2:
if a in 5..30 then
  dosomething;

5..30 ist dabei ein sog. set, weiteres: siehe Google.

mfG,
Daniel


Zuletzt bearbeitet von Hidden am Sa 02.02.08 16:01, insgesamt 1-mal bearbeitet
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 02.02.08 15:58 
ausblenden Delphi-Quelltext
1:
 if (wert >= a) and (wert <= b) then ...					

_________________
We are, we were and will not be.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 02.02.08 16:45 
@user profile iconHidden: Die Variante mit dem Set hat einige Nebeneffekte, die man im Zweifelsfall merkt, wenn's zu spät ist.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Sa 02.02.08 17:00 
ausblenden Delphi-Quelltext
1:
case wert of 2..5: {...} end;					

... um alle (?) Varianten zu erwähnen.
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Sa 02.02.08 17:01 
Der offensichtlichste Nebeneffekt ist der, das das Beispiel von Hidden gar nicht kompiliert, weil die Syntax falsch ist :lol:
if a in [0..30] then wäre korrekt.

Der zweite Nebeneffekt betrifft die Einschränkung, das eine Menge in Delphi nur Werte zwischen 0 und 255 annehmen kann.

Weitere Nebeneffekte fallen mir auf Anhieb nicht ein, außer, das es langsamer (2x) ist.

_________________
Na denn, dann. Bis dann, denn.