How to increase number?

int i = 33;
void setup() {
}
void draw() {
  for (char c = char(i); c < i+58; c++)
  println( i + " : " + c);
}

how to increase number i to 34, 35, 36, etc
thanks

1 Like

Consider using i in the for loop to increment and then
c = char(i);
in the loop.

https://processing.org/reference/for.html

I leave the rest with you.

:)

2 Likes
int i = 33;
void setup() {
    for (int j = i; j < i+58; j++){
    println( j + " : " + char(j));
  }
}
void draw() {

}

increasing i (by using i++;) inside the for loop leads to an infinite loop. (calling it in draw as well, move it to setup() to execute it once)

2 Likes

you can also increase c if you like

c++ is just short for c = c + 1

int i = 33;

void setup() {
  for (char c = char(i); c < char(i+58); c++) {
    println( int(c) + " : " + c);
  }
}

void draw() {
  //
}

Other way

or use i as a secondary variable along with c


final int startAscii = 33;

void setup() {
  size(333, 333); 

  int i=startAscii;
  for (char c = char(startAscii); c < char(startAscii+58); c++) {
    println( i + " : " + c);
    i++;
  }//for
}//func 

void draw() {
  //
}//func
1 Like
int i = 33;
void setup() {
}
void draw() {
if(i<37){i+=1}
  for (char c = char(i); c < i+58; c++)
  println( i + " : " + c);
}
1 Like

https://processing.org/reference/increment.html
https://processing.org/reference/addition.html

You could also subtract a negative number:
https://processing.org/reference/minus.html

:)

2 Likes

thank you very much all

This is one way to get the alphabet in lowercase and the code is easier to read. Even better, letter <= 'z'.

Kf

final int N_LETTERS=26;
for (char letter= 'a'; letter < 'a'+N_LETTERS; letter++) {
    println( int(letter) + " : " + letter);
}

Hello,

What was your final solution?

:)

Maybe the username? :grin:

I hope it will be @Rai

I am interested in what his solution (without referencing or cutting and pasting code) was after gleaning through this topic.

:)

1 Like

i’m ask because i don’t know what wrong with this code not because homework or something so @ForgottenCat explain to me my code wrong because put in void draw () make i in infinite loop, i ask and learn processing for my self not school or something so if i’m just copy paste from this answer i can’t get anything, i’m here to ask for learn not for copy paste @glv

please don’t think all beginners just school student ask for homework

1 Like

Hi Rai,

processing calls (=executes) the setup only once at startup. so it is great to initize any variables etc.
draw is sort of a loop. so it executes and if its finished, it restarts at the first line after draw(){. to avoid that, you have many possibilities, like “move it to setup” or check for a condition therefore moving it in some if statement.

Hello Rai,

In your original you post you shared code and asked:

You also messaged me directly and I asked you to:

I was the first to respond…

I tried to understand what you were doing, wrote some code, and gave you some direction and references. I did not share a complete solution with you; this was very achievable by you.

Your last two posts mentioned homework and school; I did not raise this point in this topic.

The community here all stepped in to help you with a lot of examples.

I was genuinely interested in what you learned from this and your final solution and I am still interested in what that is.

:)

1 Like