How can we write a TTL script to print first 10 numbers? This is what I have tried:
for i 1 10
dispstr 'i'
next
but it is not printing numbers.
According to the documentation, an integer value passed to the dispstr
command is expected to be an ASCII value. In other words, dispstr 48
would display the character 0
, dispstr 49
would display 1
, dispstr 65
would display A
and so on.
To display the integer values as integers, you can use the int2str
command to convert them to strings:
for i 1 10
int2str s i
dispstr s
next
You could also format the output using one of the sprintf
-type commands:
for i 1 10
sprintf2 s '%d' i
dispstr s
next