Bitte Kommentare beachten : darin zerpflücke ich Deinen Quelltext !
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:
| program integerzahl; uses crt; var x:integer;
function isinteger(s:string):boolean; var q:integer; c:char;
begin q:=1; while length(s) > 0 do begin c:=s[1]; case q of 1 : if c in ['+','-'] then q:= 2 else if c in ['0'..'9'] then q := 3 else q := 99; 2 : if c in ['0'..'9'] then q := 3 else q := 99; 3 : if c in ['0'..'9'] then q := 3 else q := 99; end;
delete(s,1,1); end; result := (q = 3); end; |
Ne, war doch nicht so schlimm. Wahrscheinlich nur altlasten.
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:
| function isinteger(s:string):boolean; var q:integer; c:char; begin q:=1; while length(s) > 0 do begin c:=s[1]; case q of 1 : if c in ['+','-'] then q:= 2 else if c in ['0'..'9'] then q := 3 else q := 99; 2 : if c in ['0'..'9'] then q := 3 else q := 99; 3 : if c in ['0'..'9'] then q := 3 else q := 99; end; delete(s,1,1); end; result := (q = 3); end; |
Ich habe den Source etwas abgeändert. Eine Zeile zu verschwenden für einzelnes begin, das ist zwar Borland Style Guide konform, aber nicht bei mir.

Und siehe einer mal an : es ist zeilenmäßig mehr geworden aber die Zeilen sind auch kürzer und man sieht etwas entscheidendes.

q ist immer 1. Insofern ist das nichts anderes als das hier :
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
| function isinteger(s:string):boolean; var q:integer; c:char; begin q:=1; while length(s) > 0 do begin c:=s[1]; case q of 1 : if c in ['+','-'] then q:= 2 else if c in ['0'..'9'] then q := 3 else q := 99; end; delete(s,1,1); end; result := (q = 3); end; |
Dann geht es weiter : q bleibt immer noch 1 :
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
| function isinteger(s:string):boolean; var q:integer; c:char; begin q:=1; while length(s) > 0 do begin c:=s[1]; if c in ['+','-'] then q:= 2 else if c in ['0'..'9'] then q := 3 else q := 99; delete(s,1,1); end; result := (q = 3); end; |
Und jetzt sehe ich noch, daß es bereits zu spät ist.

Letzte Kurzanalyse : q rausschmeißen !! Bool-Variable verwenden und diese als Resultat IsInteger zuweisen.
[Edit] Stimmt so auch nicht, aber ich lasse das mal trotzdem hier so stehen. Es ist doch Chaoscode. Als Sphagetti-Code kann man es allerdings kaum bezeichnen, ich würde sagen es sind Rigatoni mit zu viel Käse.
