# Repeat text x times

**URL:** <https://discourse.processing.org/t/repeat-text-x-times/31032>\
**Category:** Coding Questions\
**Created:** [July 3, 2021, 8:09pm UTC](https://discourse.processing.org/t/repeat-text-x-times/31032 "2021-07-03T20:09:00Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Post date:** [July 8, 2021, 9:18am UTC](https://discourse.processing.org/t/repeat-text-x-times/31032/21 "2021-07-08T09:18:09Z")

</div>

yeah i noticed that too

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 8, 2021, 10:33am UTC](https://discourse.processing.org/t/repeat-text-x-times/31032/22 "2021-07-08T10:33:23Z")

</div>

@MoonAlien822

Interesting topic.

I learned all about Double.POSITIVE\_INFINITY!

[https://stackoverflow.com/](https://stackoverflow.com/) has some good discussions about:  
Double.POSITIVE\_INFINITY

> [@MoonAlien822](#):
>
> if you change the x to a non infinite number it works just fine

It is important to know the sizes of data types.

References for the sizes of primitive data types:

- [https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html)
- [https://www.baeldung.com/java-primitives](https://www.baeldung.com/java-primitives)

An exercise I worked through:

```auto
println(2147483647);
println(2147483647+1); //Take a good look at the integer output for this!
//println(2147483648); See the warning for this! 
//Warning in console:
//The type *int* can't handle numbers that big. Try 2147483648L to upgrade to long.
println(2147483648L);
println();

int xInt = 2147483647;
println(xInt);
println(xInt+1);
println();

long xLong1 = 2147483647 + 1;
//println(xLong1);
System.out.println(xLong1);
println();

long xLong2 = 2147483647L + 1L;
//println(xLong2);
System.out.println(xLong2);
println();

for(int i = 2147483647-3; i>0; i++)
  {
  println(i);
  }
println();
  
for(int i = 2147483647-3; i<214748368L; i++)
  {
  println(i);
  }
println();     
  
for(int i = 2147483647-3; i<2147483647; i++)
  {
  println(i);
  }
println();   
  
//An infinite loop - uncomment this if you want to run it:
//for(int i = 2147483647-3; i<=2147483647; i++)
// {
// println(i);
// }
//println();      
    
// An infinite loop - uncomment this if you want to run it:
//for(int i = 2147483647-10; i<2147483648L; i++)
// println(i);

```

`:)`

---

<div class="post-metadata">

**Author:** ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)\
**Post date:** [July 8, 2021, 10:54am UTC](https://discourse.processing.org/t/repeat-text-x-times/31032/23 "2021-07-08T10:54:36Z")

</div>

why is this not working?

```auto
int x=19999;
int i=0;

void draw(){

if (i==0){
  print(0.);}
  
for( i=0; i<x; i++){ 
  
     if (i==x){
       print(1);
       stop();}}}

```

---

<div class="post-metadata">

**Author:** ![javagar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/javagar/32/11434_2.png) [@javagar](https://discourse.processing.org/u/javagar)\
**Post date:** [July 8, 2021, 11:19am UTC](https://discourse.processing.org/t/repeat-text-x-times/31032/24 "2021-07-08T11:19:19Z")

</div>

Just for fun, but not for the sake of efficiency, can you do it without a `for` or `while` loop?

Try this, and think about how it works:

```auto
void setup() {
  print_char_x_times('a', 20);
}

void print_char_x_times(char ch, int times) {
  if (times > 0) {
    print(ch);
    // recursive function call
    print_char_x_times(ch, times - 1);
  }
}

```

 ![print_char_x_times](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6c61f19fa8a5af928e3ffa01b5bcadcc022b0f10.png)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [July 8, 2021, 11:31am UTC](https://discourse.processing.org/t/repeat-text-x-times/31032/25 "2021-07-08T11:31:36Z")

</div>

> [@MoonAlien822](#):
>
> why is this not working?

Please use ctrl-t in processing prior to posting

It doesn’t work because for loop stops 1 before x and x is never reached

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 8, 2021, 11:34am UTC](https://discourse.processing.org/t/repeat-text-x-times/31032/26 "2021-07-08T11:34:41Z")

</div>

Hello,

> [@MoonAlien822](#):
>
> why is this not working?

It is good to develop the skills to seek out resources and examine your own code.

Example:

```auto
int x=19999;
int i=0;

void setup()
  {
  println("a", i, x);
  for(i=19990; i<x; i++)
    { 
    println("b", i, x);  
    if (i==x)
      {
      print("c", i);
      }
    }
  }

```

Reference:

- [for / Reference / Processing.org](https://processing.org/reference/for.html)

`:)`

[Previous page](https://discourse.processing.org/t/repeat-text-x-times/31032.md?page=1)
