11
Views
4
Comments
Solved
Is there a way to initialize a list ?
Question
Application Type
Reactive
Service Studio Version
11.55.50 (Build 64462)
Platform Version
11.40.0 (Build 46369)

Hi there , 

I'm trying to print the numbers from 1 to 10 to the screen, but to do that I need a list of integers of length 10 to use with a FOR-EACH loop. However, I don't know how to initialize a list of length 10.

Thanks.

2023-10-16 05-50-48
Shingo Lam
Solution

foreach is impossible in this case 

Thinking about the if condition to do the loop

  1. Define tmpInt = 0, tmpMax = 10 and tmpIntList
  2. Assign tmpInt = tmpInt + 1
  3. If tmpInt <= tmpMax, then ListAppend tmpInt to tmpIntList => back to step 2
  4. Else end

By this approach, u can change easily change the tmpMax to any number that u wanna end the list

2024-12-11 04-34-39
Peter Hieu

Hi @Hai Nguyen Ngoc 

In OutSystems, there is no built-in initialization for a list.
If you want to work with a list, you can do it in the following ways: 

  1. In your Screen, create a Local Variable named Numbers with type List of Integer.

  2. In the Screen’s OnInitialize action, create a Local Variable named TmpNumbers with type List of Integer.

  3. Still in OnInitialize, add 10 “ListAppend” steps to fill TmpNumbers with the values 1, 2, 3, …, 10.

  4. After that, call ListAppendAll to copy them into your main list:

  • Destination: Numbers

  • Source: TmpNumbers

  1. Now you can use a For Each bound to Numbers to display/print the values.


Hope this helps,

Peter Nguyen.

2021-09-06 15-09-53
Dorine Boudry
 
MVP

no need at all for that Tmp list

UserImage.jpg
Hai Nguyen Ngoc

Hi Hieu,

I understand your point, but  if i want to print the numbers from 1 to 100 to the screen? If I do it your way, it's not very feasible.

Thank you for your answer.


2021-09-06 15-09-53
Dorine Boudry
 
MVP

honestly, @Hai Nguyen Ngoc ,

OutSystems is a platform designed for business software, making a list of x numbers and print them to the screen is not likely to come up in a real application.  It sounds like an exercise for beginners to get to know the different widgets and nodes available.

And your question was about 10.


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.