Simple Question about Comment() function

 

Dear all programmer, i need your help to solve below algorithm,, 
i just would like to show it as follows : 
exp: 
1

2

3

4

5

but it didn't work, some advise will be appreciated..  :)  thnks.

int list[5] = {1,2,3,4,5};

int start() {
   for (int i = 1; i <= 5; i++) {
      Comment(list[i] + "\n");
   }  
   return(0);
}


 

It's because every time you run the function, the old comment gets overwritten.

   int list[5] = {1,2,3,4,5};

   Comment((string)list[0]+"\n"+(string)list[1]+"\n"+(string)list[2]+"\n"+(string)list[3]+"\n"+(string)list[4]);
 
int list[] = {7,2,2,9,5};

int start() {
   string com;
   for (int i = 0; i < ArraySize(list); i++) {
      string com_i = "\n " + list[i];
      com += com_i;
   }  
   Comment("\n " + "List of Number: " + com);
   return(0);
}

i apologize for this question.

i realize that what i need is add two more variables.

Thank you very much for the comment.

 
febrianto:

i apologize for this question.

i realize that what i need is add two more variables.


Thank you very much for the comment.

You can remove com_i variable. It is unnecessary and slows down the loop.

int list[] = {7,2,2,9,5};

int start() {
   string com = "";
   for (int i = 0; i < ArraySize(list); i++) {
      com += "\n " + (string)list[i];
   }  
   Comment("\n " + "List of Number: " + com);
   return(0);
}


Regards.

 
Jose Francisco Casado Fernandez:

You can remove com_i variable. It is unnecessary and slows down the loop.


Regards.


Cool Thnks.. :)

 
febrianto:

Cool Thnks.. :)

You are welcome. Regards.
Reason: