break/continue nested loop lazarus / 62-General ---------------------------------------------------------------------- riwu · 2015-12-26 06:50 Are there constructs in FPC to break/continue multi/nested loops? Or are using flags/labels the only way? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     for i:=0 to 10 do  begin    for j:=0 to 10 do    begin      if someCondition then        break(2); //break out of both loops, go to methodC       if someCondition2 then        continue(2); //break out if j loop and skip methodB       methodA();    end;     methodB();  end;   methodC(); ---------------------------------------------------------------------- eny · 2015-12-26 08:23 YAGNI ---------------------------------------------------------------------- balazsszekely · 2015-12-26 08:29 Quote@riwu Are there constructs in FPC to break/continue multi/nested loops?No. Quote@riwu Or are using flags/labels the only way? Never do that! Break down the lops to procedures/functions instead: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function LoopJ: Integer;var  J: integer;begin  Result := -1; //default, no special attention needed  for J := 0 to 10 do  begin    if SomeCondition1 then    begin      Result := 0;      Exit; //break out of both loops, go to methodC    end;     if SomeCondition2 then    begin      Result := 1;      Exit; //break out j loop and skip methodB    end;    MethodA;  end;end; procedure LoopI;var  I, Res: Integer;begin  for I := 0 to 10 do  begin    Res := LoopJ;    case Res of          0: Exit;      1: Continue;    end;    MethodB;    //you can add other stuff here  end;end; procedure TForm1.Button1Click(Sender: TObject);begin  LoopI;  MethodCend; ---------------------------------------------------------------------- guest58172 · 2015-12-26 10:40 Quote from: eny on December 26, 2015, 09:23:06 amYAGNI Some languages features look superfluous but when you need them you're happy to have them. ---------------------------------------------------------------------- eny · 2015-12-26 12:43 Quote from: BBasile on December 26, 2015, 11:40:24 amSome languages features look superfluous but when you need them you're happy to have them.We're not talking about 'some superfluous language features' but about a specific (albeit theoritical and contrived and therefore rather superfluous) question from TS. Getmem already answered more comprehensively the direction TS needs to lean towards.