Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi while not ... do (https://www.delphipraxis.net/30711-while-not-do.html)

bmg4ever 28. Sep 2004 13:03


while not ... do
 
ich hab da ein kleines Anfängerproblem mit der
while not ... do - schleife

entweder bin ich zu dumm, oder die Syntax von Delphi gefällt mir nicht ;)

Delphi-Quellcode:
while not (Tformelobjekt(formellist[i]).operator = '^') OR (Tformelobjekt(formellist[i]).operator = 'Sq')
   do inc(i);
das funktioniert nicht, wenn der operator='Sq' ist (und das ist er - das hab ich mit dem debugger geprüft).
kann man bei while keine mehreren bedingungen angeben!?

muss ich das dann so machen?

Delphi-Quellcode:
while not (Tformelobjekt(formellist[i]).operator = '^') do
begin
      while not (Tformelobjekt(formellist[i]).operator = 'Sq')
        do inc(i);
      inc(i);
end;
oder halt in zwei schleifen nacheinander. das kann doch eigentlich nicht!?
also was mach ich falsch.

Matze 28. Sep 2004 13:05

Re: while not ... do
 
Wenn beide Abfragen nicht eintreffen dürfen, musst du 2x not schreiben, falls dies dein problem ist:

Delphi-Quellcode:
while not (Tformelobjekt(formellist[i]).operator = '^') OR not (Tformelobjekt(formellist[i]).operator = 'Sq')
   do inc(i);

Dax 28. Sep 2004 13:06

Re: while not ... do
 
Mach es besser so:
Delphi-Quellcode:
while not ((Tformelobjekt(formellist[i]).operator = '^') OR (Tformelobjekt(formellist[i]).operator = 'Sq'))
   do inc(i);

bmg4ever 28. Sep 2004 13:08

Re: while not ... do
 
oh ich idiot :-D

danke vielmals, funktioniert perfekt.

alcaeus 28. Sep 2004 13:12

Re: while not ... do
 
Hi Matze,

ganz stimmt dies nicht. Laut Boolescher Algebra gilt: (not (A or B)) ist nicht ((not A) or (not B)), sondern ((not A) and (not B)).
Ich hoffe das war halbwegs verständlich, denke es einfach mal mit 0 und 1 durch, dann wirst du sehn ;)

Greetz
alcaeus

Dax 28. Sep 2004 13:13

Re: while not ... do
 
Also war meines Syntaktisch korrekt?
Faszinerend...

dizzy 28. Sep 2004 13:17

Re: while not ... do
 
Zitat:

Zitat von Matze
Delphi-Quellcode:
while not (Tformelobjekt(formellist[i]).operator = '^') OR not (Tformelobjekt(formellist[i]).operator = 'Sq')
   do inc(i);

Zitat:

Zitat von Dax
Delphi-Quellcode:
while not ((Tformelobjekt(formellist[i]).operator = '^') OR (Tformelobjekt(formellist[i]).operator = 'Sq'))
   do inc(i);

Euch ist aber klar, dass das 2 unterschiedliche Aussagen sind oder?

1) !a or !b
2) !(a or b)

Mal die 2 Wahrheitstafeln dazu (Ergebnis in Fett):
Code:
1)
!a [b]or[/b] !b
 1  [b]1[/b] 1
 1  [b]1[/b] 0
 0  [b]1[/b] 1
 0  [b]0[/b] 0

2)
[b]![/b](a or b)
[b]1[/b] 0  0 0
[b]0[/b] 0  1 1
[b]0[/b] 1  1 0
[b]0[/b] 1  1 1
1) Wenn mindestens eine der Bedingungen false ist Ergebnis true
2) Nur wenn beide Bedingungen nicht zutreffen ist Ergebnis true

Ich denke Dax's Variante dürfte das gewollte machen :).

\\edit: Alter Falter binnisch wieder laaahhhmmm :lol:

dizzy 28. Sep 2004 13:18

Re: while not ... do
 
Zitat:

Zitat von Dax
Also war meines Syntaktisch korrekt?

Sogar semantisch :zwinker:.

Matze 28. Sep 2004 13:19

Re: while not ... do
 
ja, das ist mir schon klar. ;)

Er sagte aber:
Zitat:

das funktioniert nicht, wenn der operator='Sq'
Deshalb dachte ich, er will's anders haben. :roll:

bmg4ever 28. Sep 2004 13:19

Re: while not ... do
 
Zitat:

Zitat von Dax
Also war meines Syntaktisch korrekt?
Faszinerend...

ja
ich hab deins genommen und funzt super.


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

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