Continue to end of loop

FommoFommo Member Posts: 138
edited 2008-10-28 in NAV Tips & Tricks
Hi there

Is there some nice way to accomplish the following:
WHILE (some condition) THEN BEGIN
  statement1
  IF NOT (statement1 = success) THEN
    Continue to next turn in the loop
  statement2
  IF NOT (statement2 = success) THEN
    Continue to next turn in the loop
  ... And so on ...
END;

That is some kind of "goto end of loop" or "continue to next turn" functionality. IF I would use IF - ELSE IF - ELSE IF it would be such a nasty tree of ugly indentations and after a while it will BEEP as the lines can't go over the right margin.

Comments

  • McClaneMcClane Member Posts: 40
    A case-Construct?
    while SomeCondition
      case true of
        Condition1: begin .. end;
        Condition2: begin .. end;
        .
        .
        .
        else begin .. end;
      end;
    

    Is that what you´re looking for?
  • krikikriki Member, Moderator Posts: 9,094
    WHILE (some condition) DO BEGIN
      blnContinueWithStatements := Statement1(); 
      IF blnContinueWithStatements then
        blnContinueWithStatements := Statement2(); 
      IF blnContinueWithStatements then
        blnContinueWithStatements := Statement3(); 
      ...
    END;
    

    Remark:
    Each statement must return a boolean.
    TRUE : if the code must continue with the statements
    FALSE: if the code must skip the next statements and continue with the loop.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • FommoFommo Member Posts: 138
    kriki wrote:
    WHILE (some condition) DO BEGIN
      blnContinueWithStatements := Statement1(); 
      IF blnContinueWithStatements then
        blnContinueWithStatements := Statement2(); 
      IF blnContinueWithStatements then
        blnContinueWithStatements := Statement3(); 
      ...
    END;
    

    Remark:
    Each statement must return a boolean.
    TRUE : if the code must continue with the statements
    FALSE: if the code must skip the next statements and continue with the loop.

    Quite a good idea, actually. Thanks a lot Kriki! =D>
  • krikikriki Member, Moderator Posts: 9,094
    [Topic moved from 'NAV/Navision' forum to 'NAV Tips & Tricks' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • NinlilNinlil Member Posts: 20
    WHILE SomeCondition DO BEGIN
      CASE TRUE OF
        Statement1:;
        Statement2:;
        Statement3:;
        Statement4:;
        Statement5:;
      END;
    END;
    

    All "Statement#"-function must return a Boolean.
    In each round, they are called from top to bottom until someone returns TRUE, then the CASE-statment is "solved" and the rest of the "Statements" are ignored.
    This one is probably the shortest, althou maybe not the easiest to understand for a beginner.
Sign In or Register to comment.