Continue Equiv. in C Side

wolfuliumwolfulium Member Posts: 30
So I am wanting this:
Loop through list
{
    if TODAY-item.LastRunDate < 30 {
            continue;
    }
    
    // code that adds lastrundate to item

}

I know there is a CurrReport.SKIP, however I am trying to achieve this using a CodeUnit

Thanks

Best Answer

  • wolfuliumwolfulium Member Posts: 30
    Answer ✓
    I figured the use of the work continue was self explanatory enough. I want to skip an item in a loop.

    Like the key word continue does in most of the languages. But apparently this language does not have it.


    So what I ended up doing was adding a global variable and used that.
    
    REPEAT
       continue := false;
    
       IF (date <> 0D) THEN
          IF TODAY - date < 5 THEN
             continue := true;
    
    
       IF NOT continue THEN BEGIN
     
                // code i wanted to run if the date was older than 5 days
    
       END;
    
    

Answers

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Hi,

    What exactly do you want to achieve? Loop through the Item table and do what? And stop when?

    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • xStepaxStepa Member Posts: 106
    edited 2017-10-04
    Hi, as Slawek wrote, you have to provide more info - so just guess ...
    A condition should do the same:
    FOREACH dotnetElement IN dotnetElements DO BEGIN
      IF (TODAY - dotnetElement.LastRun) >= 30 THEN BEGIN
        // handling code ...
      END
      ELSE IF counter > 12345 THEN
        BREAK; // break the loop if too many elements
      // else do nothing => continue
    END;
    
    Regards
    xStepa
  • wolfuliumwolfulium Member Posts: 30
    Answer ✓
    I figured the use of the work continue was self explanatory enough. I want to skip an item in a loop.

    Like the key word continue does in most of the languages. But apparently this language does not have it.


    So what I ended up doing was adding a global variable and used that.
    
    REPEAT
       continue := false;
    
       IF (date <> 0D) THEN
          IF TODAY - date < 5 THEN
             continue := true;
    
    
       IF NOT continue THEN BEGIN
     
                // code i wanted to run if the date was older than 5 days
    
       END;
    
    
  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Hi,

    1) REPEAT alway goes with UNTIL
    REPEAT
    UNTIL boolean
    
    2) UNTIL takes a boolean variable or expression, and stops the loop when the variable or expression evaluates to TRUE;
    3) you can use filters to limit the number of records you're looping through, instead of looping through all and running a code doing some manipulation in few cases.

    Instead of having the following code inside the loop
    IF (date <> 0D) THEN
          IF TODAY - date < 5 THEN
             continue := true;
    
    you can build an equivalent loop with a filter. Assuming that you are looping through a record variable called Item, and the record has date field::
    Item.SETFILTER(date, '<%1', TODAY - 5);
    IF Item.FINDSET THEN
    REPEAT
      //whatever is inside this loop it will be only executed
      //for Item records having the "date" field more than 5 days old 
    UNTIL Item.Next = 0;
    

    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Sign In or Register to comment.