You are on the Xporter Cloud documentation. If you are looking for Xporter Server documentation, you can find it in this page.

In this exercise, you'll learn how to iterate with the BREAK or CONTINUE statement on a Xporter generated file.

For the break functionality, let's say that you want to stop the iteration.

For the continue functionality, let's say that you want to skip to the next iteration.

Let's create the template.

As you learned on the intermediate level how to use the set function, on this exercise we are going to put it into practice on the first line.

This will set the variable count to 0:

${set(count,0)}

And below it put the #{for comments} or #{for <VariableName>=CommentsCount} statement.

Then put the set function to count +1 when entering the iteration to sum 1 to your count.

At every iteration the value of count will be count + 1:

${set(count,%{${count} + 1})}

Let's put the mappings that we want to print on the template.

MappingDescription
Author${Comments[n].AuthorFullName}
Body${Comments[n].Body}

Now, We are going to use the function continue within a conditional block.

#{if (%{'${Comments[n].Body}'.equals('Hello Continue')})}

Jump to next comment.

#{continue}

#{end}

When the comment is equal to "Hello Continue", it is going to print the message "Jump the next comment" and the iteration goes to the start of the next comment.

You must have comments on your issue and a comment with "Hello Continue".

After the conditional block with the continue statement, we are going to put another conditional block that only prints the message "Next comment".

When the count of our set function is less than CommentsCount.

#{if (%{'${count}' < '${CommentsCount}'})}

Next comment.

#{end}

Finally, close the iteration comments with #{end}.

On the same template, we are going to learn the statement break

Starting with the iteration #{for comments} or #{for <VariableName>=CommentsCount} statement.

Let's put the mappings that we want to print on the template.

Author

${Comments[n].AuthorFullName}
Body${Comments[n].Body}

Now, we are going to use the function break with a conditional block.

#{if (%{'${Comments[n].Body}'.equals('Hello Stop')})}

Finish the iteration of comments.

#{break}

#{end}

When the comment is equal to "Hello Stop", it is going to print the message "Finish the iteration of comments" and the iteration stops, skipping to its end statement.

You must have comments on your issue and a comment with "Hello Stop".

Finally, close the iteration comments with #{end}.

Below there is a sample of how the mappings will be displayed in a Word template:


This template has:

  • A header with an image
  • Headings
  • Text styling

Below there is a sample of how the generated file will be populated:

If you like this exercise, please share your opinion on the page by just leaving a comment or a (thumbs up). Your opinion is very important to us.

Thank you in advance. Enjoy our product. (big grin)

Here's the Exercise related files:

FileDescription
Exercise 1 - Template

Exercise 1 - Sample template file

Exercise 1 - GeneratedExercise 1 - Sample generated file
  • No labels