Autor Beitrag
noo.bee
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 120



BeitragVerfasst: Mo 07.06.10 20:42 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm2.BitBtn2Click(Sender: TObject);
begin
while (1=1do inc(a);

if (a>49then inc(b); a := 1;
if (b>49then inc(c); b := 1;
if (c>49then inc(d); c := 1;
if (d>49then break;

end;


warum kommt der fehler "E2097 BREAK oder CONTINUE außerhalb der Schleife" ? das break ist doch in der schleife oder nicht ? :shock:
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 07.06.10 20:45 
Moin!

user profile iconnoo.bee hat folgendes geschrieben Zum zitierten Posting springen:
warum kommt der fehler "E2097 BREAK oder CONTINUE außerhalb der Schleife" ? das break ist doch in der schleife oder nicht ?
Nein, du hast das begin/end vergessen. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Mo 07.06.10 20:45 
Ich formatier das mal richtig.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm2.BitBtn2Click(Sender: TObject);
begin
  while (1=1do 
    inc(a);

  if (a>49then inc(b); a := 1;
  if (b>49then inc(c); b := 1;
  if (c>49then inc(d); c := 1;
  if (d>49then break;
end;

Wie man sieht gehören die if Abfragen nicht mehr zur Schleife. Begin und End helfen dir weiter.

_________________
PROGRAMMER: A device for converting coffee into software.
noo.bee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 120



BeitragVerfasst: Mi 09.06.10 18:46 
ok, so sieht es jetzt aus:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
procedure TForm2.BitBtn2Click(Sender: TObject);
begin
a := 1;
b := 1;
c := 1;
d := 1;
  while (1=1do
      begin inc(d);

      if (a>49then inc(b); a := 1;
      if (b>49then inc(c); b := 1;
      if (c>49then inc(d); c := 1;
      if (d>49then break;


    if (a=b) or (a=c) or (a=d) then inc(a);
    if (b=a) or (b=c) or (b=d) then inc(b);
    if (c=a) or (c=b) or (c=d) then inc(c);

    if (a=b) or (a=c) or (a=d) then inc(a);
    if (b=a) or (b=c) or (b=d) then inc(b);
    if (c=a) or (c=b) or (c=d) then inc(c);

    if (a=b) or (a=c) or (a=d) then inc(a);
    if (b=a) or (b=c) or (b=d) then inc(b);
    if (c=a) or (c=b) or (c=d) then inc(c);

Memo1.Lines.Add(inttostr(a) + ' ' + inttostr(b) + ' ' + inttostr(c) + ' ' + inttostr(d));
edit9.Text := inttostr(memo1.Lines.Capacity);

end;
end;

aber warum sieht das ergebnis jetzt so aus und wird nicht weiter gezählt ??
ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
3 2 1 14
3 2 1 15
3 2 1 16
3 2 1 17
3 2 1 18
3 2 1 19
3 2 1 20
3 2 1 21
3 2 1 22
3 2 1 23
3 2 1 24
3 2 1 25
3 2 1 26
3 2 1 27
3 2 1 28
3 2 1 29
3 2 1 30
3 2 1 31
3 2 1 32
3 2 1 33
3 2 1 34
3 2 1 35
3 2 1 36
3 2 1 37
3 2 1 38
3 2 1 39
3 2 1 40
3 2 1 41
3 2 1 42
3 2 1 43
3 2 1 44
3 2 1 45
3 2 1 46
3 2 1 47
3 2 1 48
3 2 1 49
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Mi 09.06.10 19:10 
Öhhm, warum nimmst du nich die Lösung die wir in deinem andern Beitrag erarbeitet haben?

MfG Bergmann.

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
noo.bee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 120



BeitragVerfasst: Mi 09.06.10 19:36 
na sind die 4 for schleifen nicht VIEL rechenintensiver (quasi n^4) ? und die lösung hier wäre nur n^1 und um einiges schneller...
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Mi 09.06.10 19:43 
nee, weil du ja mit deinen Variablen das gleich machst, was die for-Schleifen machen. Am Ende is es vlt sogar langsamer, weil der Debuger die Schlifen nochma iwie optimieren kann, wenn ich mich nich irre...

MfG Bergmann

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
noo.bee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 120



BeitragVerfasst: Mi 09.06.10 20:45 
Zitat:
Am Ende is es vlt sogar langsamer, weil der Debuger die Schlifen nochma iwie optimieren kann

mhh das kann ich nicht beantworten bzw beurteilen

ich hab einfach versucht, das ganze logisch zu sehen. wenn 4 for schleifen durchlaufen werden müssen ist das langsamer, als bei meiner version - hatte ich zumindest geglaubt
bole
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 107
Erhaltene Danke: 15

win 10

BeitragVerfasst: Mi 09.06.10 21:06 
Hallo

BREAK ist ein verkapptes GOTO!

Meiner Erachtens zeugt es nicht von gutem Programmierstil eine Endlosschleife zu programmieren und diese mir Break zu verlassen...

Ich will nicht unbedingt sagen es gibt keine Sinnvollen Verwendung von Break und Goto jedoch sollte man diese nach Möglichkeit vermeiden und nur sehr sparsam verwenden. Die Übersicht und Wartbarkeit werden durch den Gebrauch nicht wirklich verbessert!

Gruss
Bole

_________________
ein programm macht nicht das was du willst sondern was du schreibst!
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Mi 09.06.10 21:15 
user profile iconnoo.bee hat folgendes geschrieben Zum zitierten Posting springen:
ich hab einfach versucht, das ganze logisch zu sehen. wenn 4 for schleifen durchlaufen werden müssen ist das langsamer, als bei meiner version - hatte ich zumindest geglaubt
Beide erzeugen gleich viele Zahlen, beide werden ziemlich genau die gleiche Laufzeit haben. Und, welche Version ist lesbarer ;) ?

_________________
>λ=
noo.bee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 120



BeitragVerfasst: Mi 09.06.10 21:24 
ok ok, lesbarer is dir for variante ;) ;)

wollt noch n prob geklärt haben. wenn ich "e" und "f" mit einbaue und die zufällig bestimmen lasse durch
ausblenden Delphi-Quelltext
1:
2:
e := random(18)+1;// zufall zwischen 1 und 19
f := random(18)+1;


an welche stelle wird es "eingabaut" ? egal wo ich es einbaue, es gibt überall fehler. aber irgendwo muss es doch "passen" und es muss auf jeden fall noch VOR Memo1.Lines.Add(....)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
procedure TForm2.BitBtn2Click(Sender: TObject);
var a, b, c, d, e, f: Integer;
const MAX = 19;
e := random(18)+1;// zufall zwischen 1 und 19
f := random(18)+1;
begin
  for a := 1 to MAX do
    for b := a+1 to MAX do
      for c := b+1 to MAX do
        for d := c+1 to MAX do
            

          Memo1.Lines.Add(
            IntToStr(a)+' '+
            IntToStr(b)+' '+
            IntToStr(c)+' '+
            IntToStr(d)+' '+
            IntToStr(e)+' '+
            IntToStr(f));

edit9.Text := inttostr(memo1.Lines.Capacity);
end;
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Do 10.06.10 01:31 
Hey,

wie wärs wenn du es nach dem begin der Prozedur "einbaust"? ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
procedure TForm2.BitBtn2Click(Sender: TObject);
var a, b, c, d, e, f: Integer;
const MAX = 19;
begin
e := random(18)+1;// zufall zwischen 1 und 19
f := random(18)+1;
  for a := 1 to MAX do
    for b := a+1 to MAX do
      for c := b+1 to MAX do
        for d := c+1 to MAX do
            

          Memo1.Lines.Add(
            IntToStr(a)+' '+
            IntToStr(b)+' '+
            IntToStr(c)+' '+
            IntToStr(d)+' '+
            IntToStr(e)+' '+
            IntToStr(f));

edit9.Text := inttostr(memo1.Lines.Capacity);
end;
MfG Bergmann

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
noo.bee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 120



BeitragVerfasst: Do 10.06.10 12:17 
hatte ich schon. aber da kommt:

unit name "controls" kann nicht aufgelöst werden. ich habs bei uses mit drin
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Do 10.06.10 15:02 
Das ist aber kein Compiler Fehler, oder?

Ist nen bekanntes Problem in den neueren Delphi Versionen. Da zickt dieses Error Insight manchmal rum, und zeigt fehlende Units und so weiter an, obwohl das Programm trotzdem normal läuft.

_________________
PROGRAMMER: A device for converting coffee into software.
noo.bee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 120



BeitragVerfasst: Do 10.06.10 19:45 
Zitat:
wie wärs wenn du es nach dem begin der Prozedur "einbaust"?

es soll ja bei jedem durchlauf mit drin sein. aber egal wie ich es in/nach den for-schleifen einbaue, es funzt nicht...

mhhh, wie schon gesagt. in uses is ja controls drin... kann ich die fehler "umgehen" ?
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Do 10.06.10 19:50 
user profile iconnoo.bee hat folgendes geschrieben Zum zitierten Posting springen:
mhhh, wie schon gesagt. in uses is ja controls drin... kann ich die fehler "umgehen" ?


Nochmal: Lässt sich das Programm trotzdem compilieren und starten? Wenn ja, brauchst du den Fehler nicht zu umgehen, sondern kannst ihn ignorieren..
Bei mir hilft es in diesen Situationen manchmal, Delphi zu schließen und neu zu öffnen.

_________________
PROGRAMMER: A device for converting coffee into software.
noo.bee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 120



BeitragVerfasst: Do 10.06.10 19:54 
naja das prob liegt wohl am pc. hier an dem pc gehts - da kommt keine fehlermeldung. an unserem anderen gibts den fehler. da lässt es sich nicht kompilieren. seltsam :(

ok, zurück zum thema ;) am 2. pc gehts

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm2.BitBtn2Click(Sender: TObject);
var a, b, c, d, e, f : Integer;
const MAX = 49;
begin
e := random(48)+1;// zufall zwischen 1 und 49
f := random(48)+1;
  for a := 1 to MAX do
    for b := a+1 to MAX do
      for c := b+1 to MAX do
        for d := c+1 to MAX do
...

geht nicht. und in die for schleifen bekomm ichs net rein. dann ist "e" und "f" immer 1 und 2 und nicht random(48)+1
Stundenplan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128
Erhaltene Danke: 32

Win 7
Delphi 7 Pers., C# (VS 2010 Express)
BeitragVerfasst: Do 10.06.10 20:29 
Hast du denn schon randomize vor den randoms probiert?
Und wie bekommst du das net rein? Einfach begin/end verwenden:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
procedure TForm2.BitBtn2Click(Sender: TObject);
var a, b, c, d, e, f: Integer;
const MAX = 19;
begin
  randomize;
  for a := 1 to MAX do
    for b := a+1 to MAX do
      for c := b+1 to MAX do
        for d := c+1 to MAX do
          begin
            e := random(18)+1;// zufall zwischen 1 und 19
            f := random(18)+1;
            Memo1.Lines.Add(
                        IntToStr(a)+' '+
                        IntToStr(b)+' '+
                        IntToStr(c)+' '+
                        IntToStr(d)+' '+
                        IntToStr(e)+' '+    
                        IntToStr(f));
           edit9.Text := inttostr(memo1.Lines.Capacity);
         end;
end;

Oder hab ich jetz das Problem falsch verstanden?
noo.bee Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 120



BeitragVerfasst: Do 10.06.10 20:35 
:roll: hab randomize; vergessen :roll: den rest hatte ich
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Do 10.06.10 21:32 
Ich verlier hier grad den Überblick, was nun aktuell ist..

Kannst du das Programm compilieren?
- Wenn nicht: Wie sieht dein aktueller Code aus? Welche Fehlermeldung wird vom Compiler angezeigt?

_________________
PROGRAMMER: A device for converting coffee into software.