Create a list to store integers using Types::Integer.
Number: 1 Number: 2 Number: 3 Number: 4 Number: 5 Number: 6 Number: 7 Number: 8 Number: 9 Number: 10
internal final class ListExampleDemo
{
/// <summary>
/// Entry point of the program.
/// Demonstrates how to use a List and ListIterator in X++
/// </summary>
/// <param name="_args">Runtime arguments passed to the program.</param>
public static void main(Args _args)
{
// Step 1: Initialize a list to store integers
List integerList = new List(Types::Integer);
ListIterator listIterator;
int currentNumber;
// Step 2: Add numbers from 1 to 10 to the list
for (currentNumber = 1; currentNumber <= 10; currentNumber++)
{
integerList.addEnd(currentNumber);
}
// Step 3: Initialize an iterator to traverse the list
listIterator = new ListIterator(integerList);
// Step 4: Traverse and print each number in the list
while (listIterator.more())
{
int numberToPrint = listIterator.value(); // Get the current value
print strFmt("Number: %1", numberToPrint); // Print the value
listIterator.next(); // Move to the next element
}
// Step 5: Pause to allow the user to view the output
pause;
}
}
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.
Sign in to save your progress and continue exactly where you left off.