How to skip one iteration in a loop ("Repeat" statement) with 4GL?

SOLVED

Hi

I'm iterating trough a list of objects using a repeat statement. If a specific criteria matches, I want to skip the code for the current object in the loop.

How do I achieve this? The "break" statement ends the whole repeat statement, I just want to ignore the rest of the code in the loop for one item and continue with the next item in the list.

In other languages, I can use the "continue" keyword. What's the magic word in Sage X3?

Example:

Local Integer TOTAL_ROWS, CURRENT_ROW
[L]TOTAL_ROWS = 10
[L]CURRENT_ROW = 0
Repeat
  [L]CURRENT_ROW += 1
  If([L]CURRENT_ROW = 5)
    # To Do: Skip current row
  Endif
  Infbox num$([L]CURRENT_ROW)
Until [L]CURRENT_ROW = [L]TOTAL_ROWS

Thx & Regards
Benjamin

  • +1
    verified answer

    Benjamin,

    I don't know your specific situation, but it would make sense to me to do something like:

    Local Integer TOTAL_ROWS, CURRENT_ROW
    [L]TOTAL_ROWS = 10
    [L]CURRENT_ROW = 0
    Repeat
      [L]CURRENT_ROW += 1
      If [L]CURRENT_ROW <> 5
        # Do things here
      Endif
      Infbox num$([L]CURRENT_ROW)
    Until [L]CURRENT_ROW = [L]TOTAL_ROWS

    That way, you are effectively testing that your 'skip' conditions are NOT met, and then doing your logic in those cases. In other cases (depending on the tests I need to check) I've done something like:

    Local Integer TOTAL_ROWS, CURRENT_ROW
    [L]TOTAL_ROWS = 10
    [L]CURRENT_ROW = 0
    Repeat
      [L]CURRENT_ROW += 1
      If [L]CURRENT_ROW = 5
        # Skip row
      Else
        # Do things here
      Endif
      Infbox num$([L]CURRENT_ROW)

    Until [L]CURRENT_ROW = [L]TOTAL_ROWS

  • +1 in reply to Michael C. Bell
    verified answer

    Hello Michael

    Thanks for your reply, I apreciate that. I found another solution, where I do not need to rewrite my conditions.

    We can set a label at the position we want to "jump" to and use "Goto" to skip the code 

    Local Integer TOTAL_ROWS, CURRENT_ROW
    [L]TOTAL_ROWS = 10
    [L]CURRENT_ROW = 0
    Repeat
      [L]CURRENT_ROW += 1
      If([L]CURRENT_ROW = 5)
        Goto CONTINUE
      Endif
      Infbox num$([L]CURRENT_ROW)
      $CONTINUE
    Until [L]CURRENT_ROW = [L]TOTAL_ROWS

    Seems like a pretty solution, doesn't it?

    Best regards, Ben

  • 0 in reply to Benjamin Eich

    I'm glad you found something that works for you!