Not able to pass Variable in For Loop

Hi,

I am taking String from the serial which is "up87" and "down90". In this, the numbers changes but the letters remains the same.

so by using :

void loop()
{
  if (Serial.available())
  {
    String data = Serial.readStringUntil('\n');
    data.trim();
    Serial.println(data);
    delay(50);
    String part01 = getValue(data,',',0);
    String part02 = getValue(data,',',1);
    Serial.println(part01);
    Serial.println(part02.toInt());
    
    if (part01 == "up"){
      Serial.println(part02.toInt());
      //part02 = part02.toInt();
      part02 = atoi(part02)
      delay(50);
      for (part02.toInt() ; part02.toInt() > 0 ; part02.toInt()++){
        mySender.send(tv_volume_up,RAW_DATA_LEN,38);//Pass the buffer,length, optionally frequency
        Serial.println(F("TV is Rocking"));
        delay(40);

In the above code, I am getting "up" in part01 and "87" in part02. So now I want to pass this part02 in for loop. The number's purpose is to run the loop that many times and send the IR signal to the TV. It's like the user is asking for that times of percentage volume to be up.

But when I pass that in for loop it gives me Error : cannot convert 'String' to 'const char*' for argument '1' to 'int atoi(const char*)'

So how can I achieve it? Please help regarding it.

for (part02.toInt() ; part02.toInt() > 0 ; part02.toInt()++){
        mySender.send(tv_volume_up,RAW_DATA_LEN,38);//Pass the buffer,length, optionally frequency
        Serial.println(F("TV is Rocking"));
        delay(40);

Even if that could work, you would keep converting the same string to a number over and over and getting the same number.

get it into a variable you can use first.

int someVariable = part02.toInt();

for (int i = part02.toInt(); i>0; i++){

Although that looks like it probably isn't right either. Usually a ++ loop is checking for a value to be less than something.

Hi,

So what do you think should be the solution to this? I was also trying different things but didn't seem to work.

If anyone has any idea please give me some...

Write something like

int x = part02.toInt() and use that actual number variable in your for loop.