Search code examples
javascriptimacros

IMacro JavaScript; Loop on IF else statement


for(var i=0;i<1;i++)
{ 
    iimPlay(macro_var)
    var extract=iimGetLastExtract();
    if(extract.toLowerCase()=="incorrect security code entered!")
    {
        iimDisplay("wrong") 
    }
    else
    {
        iimDisplay("right")
    }
}

That's my imacro code (Javascript File) If i get wrong how i do get it to try again until it reaches right?


Solution

  • Supposing you don't want to wait between executions, there are a couple of ways you could do this. The quickest one would be:

    while(true) {
        iimPlay(macro_var);
        var extract = iimGetLastExtract();
        if (extract.toLowerCase() == "incorrect security code entered!") {
            iimDisplay("wrong");
            continue;
        } else {
            iimDisplay("right");
            break;
        }
    }
    

    In this way, when the extracted value is wrong you restart the loop. If instead it's right, you break out of the loop.