All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.delphi.rules.community-delphi.GotoStatement.html Maven / Gradle / Ivy

There is a newer version: 1.12.1
Show newest version

Why is this an issue?

goto is an unstructured control flow statement. It makes code less readable and maintainable, and is not recommended in modern code.

How to fix it

Use condition variables with structured control flow statements such as if, for, while, Continue, or Break instead.

  function Foo: Boolean;
  var
    Sentence: string;
  begin
    for I := 1 to 10 do begin
      Sentence := Sentence + Readln;

      if Input = '.' then begin
        goto SentenceEnded;
      end;
    end;

    ShowMessage('Cutting off the sentence here');
  SentenceEnded:
    ShowMessage('Sentence: ' + Sentence);
  end;
function Foo: Boolean;
var
  Sentence: string;
  SentenceShown: Boolean;
begin
  for I := 1 to 10 do begin
    Sentence := Sentence + Readln;

    if Input = '.' then begin
      ShowMessage('Sentence: ' + Sentence);
      SentenceShown := True;
      Break;
    end;
  end;

  if not SentenceShown then begin
    ShowMessage('Cutting off the sentence here');
    ShowMessage('Sentence: ' + Sentence);
  end;
end;

Resources





© 2015 - 2024 Weber Informatics LLC | Privacy Policy