Autor Beitrag
bonanza
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: Mi 23.11.05 14:54 
HI,

wie kann ich bei der for-schleife verändern, dass er nicht wie hier:

ausblenden Delphi-Quelltext
1:
for i:=1 to 100 do Zahlen[i]:=true;					


immer +1 rechnet sondern +2 ?

danke schonmal im voraus

bonanza
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 23.11.05 15:21 
Ne wirkliche Lösung weiß ich auch nicht aber du könntest das vielleicht so machen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
for i := 1 to 100 do
begin
//prüfen, ob i eine gerade Zahl ist
//wenn, dann müsste die ganzzahldivision durch 2 gleich der normalen division durch 2 sein
//du könntest auch mit i div 2 mod arbeiten und prüfen, ob mod 0 ist.
//weiß aber die passende Syntax grad nich
if (i div 2)=(i/2) then zahlen[i]:=true;
end;

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Mi 23.11.05 15:31 
das geht in Delphi nicht, Du kannst es aber wie folgt abbilden !
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
i := 0;
while i <=100 do
begin
  //hier etwas tun mit dem Wert von I 
  i := i+2;
end;

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.


Zuletzt bearbeitet von chrisw am Mi 23.11.05 15:32, insgesamt 2-mal bearbeitet
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Mi 23.11.05 15:31 
Gruss !
Probiers mal So in der for bzw repeat Schleife.


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.Button1Click(Sender: TObject);
var
 i:Integer;
begin
  for i := 1 to 100 div 2 do {durch 2}
 begin
  Listbox1.Items.Add(IntToStr(i*2)); {mal 2}
 end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
 i:integer;
begin
  i:=0;
 repeat {Solage wiederholen}
  inc(i,2); {i erhöhen um 2}
  Listbox1.Items.Add(IntToStr(i));
 until i >=100; {bis 100 oder größer > nicht vergessen ! falls zb.um 3 erhöht wird wird 100 nie ereicht.}
end;
Grishnak
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 221

Windows XP Home
Delphi 7 PE, Delphi 2005 PE
BeitragVerfasst: Mi 23.11.05 17:55 
ausblenden Delphi-Quelltext
1:
2:
for i:=1 to 50 do
  Zahlen[i*2]:=true;

_________________
Mach' etwas idiotensicher und irgendjemand erfindet einen besseren Idioten!