+2 votes

How do I output a collection variable (with unknown size) as a list? When I just write {myCollection} in the text, items are comma separated. I want them as individual list items. Since the size is unknown, I can't simply use *list with {myCollection[1]} etc. because I would need a dynamic number of lines for this. Haven't found a way yet to make lists with dynamic length.

by (5.8k points)

1 Answer

+1 vote

There is surprisingly no straightforward solution but here are three different approaches you might use:

https://www.guidedtrack.com/programs/15666/edit

This approach does not use actual *list:

>> i = 1
*while: i <= fruits.size
	• {fruits[i]}
	>> i = i + 1



This approach creates *list for each element, it won't work for ordered lists.

>> i = 1
*while: i <= fruits.size
	*list
		{fruits[i]}
	>> i = i + 1

This one is a trick to act as if we generate list dynamically. With this approach you can have expandable or enumerated lists.

>> collection = fruits
*program: list of variable length

list of variable length program.

by (5.8k points)

Thanks for this!

No super satisfying solution, but it'll do the job. :)

I admit it would be nice if the "guidedtrack language" would involve the possibility of actual programming, as the language as it is is really not very expressive. But I guess it's possible to get most of the things done you'd usually want to have in such an online course, so it might be good enough as more dynamic programming components would do more harm than good due to introducing potentially many bugs.

Welcome to Guidedtrack Q&A, where you can ask questions and receive answers from other members of the community.
134 questions
144 answers
55 comments
40 users