how do I replicate this using a for loop?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Anzol8

for example:

if the user types: 4

program shows:
1
12
123
1234

if the user types: 12

program shows:
1
12
123
1234
12345
123456
1234567
12345678
123456789
12345678910
1234567891011
123456789101112

how do I do this in godot?

:bust_in_silhouette: Reply From: Ninfur
var count: int = 12

var output: String
for i in range(1, count + 1):
	output += str(i)
	print(output)

this does’t work, it only prints 123456789101112

instead of:

1
12
123
1234
12345
123456
1234567
12345678
123456789
12345678910
1234567891011
123456789101112

Anzol8 | 2022-11-27 18:17

Make sure the print-statement is inside the for-loop, exactly as shown in the answer and it will print multiple lines. Also make sure you are using tabs and not spaces when indenting.

Ninfur | 2022-11-27 22:03

oh ok, thanks, it wasn’t inside the for-loop, problem solved.

Anzol8 | 2022-11-28 00:25