Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Bedingte Bedingung (https://www.delphipraxis.net/3119-bedingte-bedingung.html)

nailor 24. Feb 2003 14:58


Bedingte Bedingung
 
Delphi-Quellcode:
var a,b,c,res: boolean;
begin

if a then
  res := b and c
else
  res := b;

if res then
  ...

end;
geht das auch in eine Zeile, nach dem Motto

Delphi-Quellcode:
var a,b,c,res: boolean;
begin

if (res := if a then (b and c) else b) then
  ...

end;

eddy 24. Feb 2003 15:19

Hallo Nailor,

ja:

Code:
if a then res := b and c else res := b;
:mrgreen: :mrgreen:

mfg
eddy

oki 24. Feb 2003 15:20

Sieht gut aus. Ein Test würde uns im Zweifelsfall belehren.

Gruß oki

@ hab Eddy's Beitrag nicht gesehen. Der ist so richtig wirklich nicht ein Beitrag. Alles nur in eine Zeile schreiben ist keine Kunst und Die Prüfung auf res fehlt ganz.

sakura 24. Feb 2003 15:26

Wie gemein :roll: Ich denke mal, was Oki wollte ist

Delphi-Quellcode:
res := (a and b and c) or ((not a) and b);
if res then
  ...
oder kürzer
Delphi-Quellcode:
if (a and b and c) or ((not a) and b) then
  ...

eddy 24. Feb 2003 15:31

Hallo Nailor,

die vorige Antwort war nur Spaß!! :mrgreen:

Hier nun eine - hoffentlich - vernünftige Antwort:

res wird wahr, wenn a wahr ist und b und c oder wenn a fasch aber b = wahr
wenn res nicht noch zwischen if res then ... end benutzt wird
Code:
if (a and b and c) or b then
  ....
end;
mfg
eddy

oki 24. Feb 2003 15:32

Ja klar, so siehts aus. Hier ist dann nur noch die Frage zu klären ob res als "Hilfsvariable" für die Abfrage erstellt wurde oder Das Ergebnis auf Res im Folgenden noch benötigt wird (dann nehm ich auch immer Ergebnisvariablen um die Wiederholung solcher Horror-Verknüpfungen zu vermeiden [und hab da dann mal einen Fehler drin :bouncing4: ]).

Gruß oki

eddy 24. Feb 2003 15:36

Hallo Leute,

mein erster Kommentar war nur Spaß und mein zweiter auch noch fehlerhaft.

Sakura hat's so geschrieben, wie ich es mit richtig nachdenken auch geschrieben hätte.

Am besten, ein Moderator löscht alle drei Kommentare (aber nur wenn das nicht zu viel Aufwand ist).

mfg
eddy :freak:

nailor 24. Feb 2003 16:24

Zitat:

Zitat von sakura
Wie gemein :roll: Ich denke mal, was Oki wollte ist

Delphi-Quellcode:
res := (a and b and c) or ((not a) and b);
if res then
  ...
oder kürzer
Delphi-Quellcode:
if (a and b and c) or ((not a) and b) then
  ...

:wall: :wall: :wall: :wall: :wall: Das ist alles was ich dazu sagen. Mit Genugtuung stell ich fest, dass ich nicht nur mich verwirrt habe :twisted:

Damit ist die Sache wohl geklärt,

...außer wir machen ne neue Abteilung "What does this evaluate to?" auf, mit lustigem boolean-Rechnen für alle :wink:


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:17 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz