AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Bedingte Bedingung

Ein Thema von nailor · begonnen am 24. Feb 2003 · letzter Beitrag vom 24. Feb 2003
Antwort Antwort
Benutzerbild von nailor
nailor

Registriert seit: 12. Dez 2002
Ort: Karlsruhe
1.989 Beiträge
 
#1

Bedingte Bedingung

  Alt 24. Feb 2003, 14:58
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;
Michael N.
http://nailor.devzero.de/code/sharpmath/testing/ --- Tests, Feedback, Anregungen, ... aller Art sehr willkommen!
::: don't try so hard - it'll happen for a reason :::
  Mit Zitat antworten Zitat
Benutzerbild von eddy
eddy

Registriert seit: 3. Jan 2003
Ort: Sachsen
573 Beiträge
 
Delphi 5 Professional
 
#2
  Alt 24. Feb 2003, 15:19
Hallo Nailor,

ja:

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


mfg
eddy
  Mit Zitat antworten Zitat
oki

Registriert seit: 30. Dez 2002
Ort: Brandshagen
1.819 Beiträge
 
Delphi 2007 Professional
 
#3
  Alt 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.
  Mit Zitat antworten Zitat
Benutzerbild von sakura
sakura

Registriert seit: 10. Jun 2002
Ort: München
11.412 Beiträge
 
Delphi 11 Alexandria
 
#4
  Alt 24. Feb 2003, 15:26
Wie gemein 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
  ...
Daniel W.
Ich bin nicht zurück, ich tue nur so
  Mit Zitat antworten Zitat
Benutzerbild von eddy
eddy

Registriert seit: 3. Jan 2003
Ort: Sachsen
573 Beiträge
 
Delphi 5 Professional
 
#5
  Alt 24. Feb 2003, 15:31
Hallo Nailor,

die vorige Antwort war nur Spaß!!

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
  Mit Zitat antworten Zitat
oki

Registriert seit: 30. Dez 2002
Ort: Brandshagen
1.819 Beiträge
 
Delphi 2007 Professional
 
#6
  Alt 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 ]).

Gruß oki
  Mit Zitat antworten Zitat
Benutzerbild von eddy
eddy

Registriert seit: 3. Jan 2003
Ort: Sachsen
573 Beiträge
 
Delphi 5 Professional
 
#7
  Alt 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
  Mit Zitat antworten Zitat
Benutzerbild von nailor
nailor

Registriert seit: 12. Dez 2002
Ort: Karlsruhe
1.989 Beiträge
 
#8
  Alt 24. Feb 2003, 16:24
Zitat von sakura:
Wie gemein 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
  ...
Das ist alles was ich dazu sagen. Mit Genugtuung stell ich fest, dass ich nicht nur mich verwirrt habe

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
Michael N.
http://nailor.devzero.de/code/sharpmath/testing/ --- Tests, Feedback, Anregungen, ... aller Art sehr willkommen!
::: don't try so hard - it'll happen for a reason :::
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:04 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