For Loop

aman_mbsaman_mbs Member Posts: 158
How To Break / Exit For Loop......

Aman
Aman Kumar Gupta

Comments

  • MbadMbad Member Posts: 344
    Make the 'to' statement true...
  • kinekine Member Posts: 12,562
    Mbad wrote:
    Make the 'to' statement true...

    Or not use "for loop" when you need "while" or "repeat until" instead... :-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • MbadMbad Member Posts: 344
    kine wrote:
    Mbad wrote:
    Make the 'to' statement true...

    Or not use "for loop" when you need "while" or "repeat until" instead... :-)

    Only time i used for so far was doing a true downto false. Neat lil thing.
  • krikikriki Member, Moderator Posts: 9,110
    kine wrote:
    Mbad wrote:
    Make the 'to' statement true...

    Or not use "for loop" when you need "while" or "repeat until" instead... :-)
    It is not advised (AND bad programming practice) to change the value of the looping variable in the for-loop. So better do like kine says.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • MbadMbad Member Posts: 344
    kriki wrote:
    It is not advised (AND bad programming practice) to change the value of the looping variable in the for-loop. So better do like kine says.
    Never said anything about changing the variable. Pretty sure we agree that for loops are rarely used in NAV.
  • krikikriki Member, Moderator Posts: 9,110
    Mbad wrote:
    kriki wrote:
    It is not advised (AND bad programming practice) to change the value of the looping variable in the for-loop. So better do like kine says.
    Never said anything about changing the variable. Pretty sure we agree that for loops are rarely used in NAV.
    True, they are very rarely used.

    But how do you want to make the to-statement true? Or you let it finish or you change the looping-variable in the loop.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DenSterDenSter Member Posts: 8,307
    It's an easy decision really. Use FOR when you know exactly how many times you are going to loop. Use REPEAT UNTIL or WHILE when you don't know how many times. REPEAT if you have to loop at least once, WHILE if you don't.

    I cheat on that though, I like using UNTIL, in case I ever need to add an evaluation. :mrgreen:
Sign In or Register to comment.