Announcement

Collapse
No announcement yet.

Concatenation format?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Concatenation format?

    Hi. I have ten variables, myvar1, myvar2 ... myvar10, and would like to run a conditional statement on them. For example, is myVar1 greater than the other nine variables, myvar2 through myvar10. Rather than write nine separate conditional statements I'd like to use one conditional within a loop. Something like the following:

    for(i=2; i < 10; ++i) {
    i= toString();
    if(myVar1 >= FORMAT UNKNOWN) {
    Color0=Color.lime }
    }

    First question, am I correct that I need to convert "i" to a string?

    Second question, where I have written FORMAT UNKNOWN what would be the correct format to concatenate the "i" strings to a base variable, for example myvar+"i" to generate myvar2, myvar3, etc.?

    Finally, would I then need to convert "i" back to a number object by multiplying it by 1? E.g. inserting the line

    i=i*1;

    before the final bracket? Thanks for any suggestions.

    Mike

  • #2
    Mike
    Assuming your variables are named myVar1 through myVar10 here is how you would need to structure the for loop
    Alex

    PHP Code:
    for (var i=2i<=10i++){
        if(
    myVar1 >= eval("myVar"+i)){
            
    debugPrintln("true "+"myVar"+i);
        }

    Comment


    • #3
      Thanks Alexis.

      Mike

      Comment


      • #4
        Mike
        You are most welcome
        Alex

        Comment

        Working...
        X