# Repeating a text controlled by boolean value.

rsingkhuwal4445 shared this question 2 years ago

How can i repeat a same text many times controlled by a boolean value? What exactly do you mean? Something simple as the following?

```repeat = true
If(repeat, Sum(Sequence("foo", k, 1, 10)), "foo")``` 1

What exactly do you mean? Something simple as the following?

```repeat = true
If(repeat, Sum(Sequence("foo", k, 1, 10)), "foo")``` 1

Thank You so much. This is what i wanted 1

If l1={0,1,2,3,5}

and l2=Sequence(Sequence(If(Element(l1, j) > 0, "A", ""), k, 1, Element(l1, j)), j, 1, Length(l1))={{},{A},{A,A},{A,A,A},{A,A,A,A,A}}

but why is l3=Sequence(Sum(Element(l2, i)), i, 1, Length(l2))={0,?,?,?,?}

i am looking for {"","A","AA","AAA","AAAAA"} 1

Lists in GeoGebra are only guaranteed to work properly if all the elements have the same type, otherwise weird stuff might happen. Also, you have to rely on GeoGebras own interpretation for the type of an object. And here this clashes: When GeoGebra calculates the first element of the list l3, it sums over an empty list and considers the result to be a number. At that point GeoGebra considers the list it is creating to be a list of numbers and tries to interpret all the following sums as sums of numbers, and that fails. You can easily see that the problem doesn't happen if l1 starts with a non-zero number. (But you have to redefine l3, so that Geogebra "forgets" that it is a list of numbers.)

To avoid this sort of problem when working with lists of strings, I suggest to never use empty lists but rather use a list with an empty string instead. For example you could define l2 as

`l2=Sequence(If(Element(l1, j) > 0, Sequence("A", k, 1, Element(l1, j)), {""}), j, 1, Length(l1))`

Btw, whenever you use "Sequence(<Expression>, j, 1, Length(<List>))" where <Expression> uses j only for "Element(<List>,j)", then it's easier to write with the Zip command. For example the line above could be written as

`l2=Zip(If(n > 0, Sequence("A", k, 1, n), {""}), n, l1)`

and l3 could be defined as

`l3=Zip(Sum(L), L, l2)`

Also, are you actually using the list l2 for anything else? If not you could just define l3 directly as

`l3=Zip(If(n > 0, Sum(Sequence("A", k, 1, n)), ""), n, l1)`

without needing l2 at all. 