Highlighted

While loop with Or statement

Avatar

Guest

10-06-2008

Is it possible to have a while loop with the or (||) comparison.



I've been trying while (x != 1 || 2) and variations such as while (x != 1 || x != 2).



When I have just one statement the loop performs as normally, but when I add the second argument it seems to become an infinite loop, I've tested to make sure the variable is updating so I'm pretty sure the problem lies in my loop statement.



I am fairly new to javascript so this might be a case of me trying to use features from other languages that arent available in javascript.



Thank you



Paul

Replies

Highlighted

Robert_Hirst

10-06-2008

I'm pretty sure any valid boolean expression can be used in a while loop, and I don't see anything wrong using with your second version (x != 1 || x != 2). However I don't think that with that statement any value of x will allow the OR statement to evaluate to false, so the loop will continue forever:



x=0 = ( true || true ) = result true

x=1 = ( false || true ) = result true

x=2 = ( true || false ) = result true

x=3 = ( true || true ) = result true



Perhaps you mean to use the AND operator && which would mean the loop would break if x was either 1 or 2.
Highlighted

Avatar

Guest

11-06-2008

whenever ive tried to use the && operator it generates the following error:



XML parsing error: not well-formed (invalid token) (error code 4), line 59, column 23 of file.



This is a sample of the loop ive been trying to use:



var Temp = 1;



while (Temp != 2 && Temp != 3)

{

Temp = app.response({

cQuestion: "Enter Temp",

cTitle: "Testing:",

cDefault: "",

});

TextField1.rawValue = Temp;

}
Highlighted

Robert_Hirst

12-06-2008

All that syntax appears to be fine (I'm assuming app.response is a method you have defined elsewhere), which part exactly in that code equates to line 59, column 23?



I put this on a click event of a button (only slightly modified to define a replacement for app.response):



>var Temp = 1;



>while (Temp != 2 && Temp != 3)



>{



>Temp = response({



>cQuestion: "Enter Temp",



>cTitle: "Testing:",



>cDefault: "",



>});



>TextField1.rawValue = Temp;



>}



>function response(obj) {



> xfa.host.messageBox("o:"+obj.cTitle);



> return 2;



>}



Works ok for me. Are you using Designer ES, and have you tried the validate syntax function (book with a green tick above script window) and looked for errors?
Highlighted

Robert_Hirst

12-06-2008

OK, just checked on app.response and it's an Acrobat scripting method I wasn't familiar with. I assume that the code you have is for calling it in Acrobat scripting, as you wouldn't call it with an object which has certain properties like that in Designer.



Should be:



>var Temp = 1;



>while (Temp != 2 && Temp != 3)



>{



>Temp = app.response("Enter Temp","Testing:","");



>TextField1.rawValue = Temp;



>}
Highlighted

Avatar

Guest

12-06-2008

Thanks for the help, the code is called from a button click event.



I tried out both sets of code you posted and both generate the same error I have been receiving. The line mentioned in the error is the while statement. There seems to be something about the && operator that my copy of LiveCycle doesnt like.



I know that in C++ and VB you sometimes have to include libraries in your code to allow certain functions, does javascript have anything like that? It just seems odd that || is allowed but && so far has not been.



Again thanks for the help
Highlighted

Robert_Hirst

12-06-2008

No, the only thing is that the script must be set to Javascript and not Formcalc from the drop down at the top corner of the script editor, but I would think you've already done this or the || wouldn't work either.



If you navigate to the exact Line/Column indicated by the error message, is it actually the & character there, or something else?
Highlighted

Avatar

Guest

28-07-2008

hi,

Can u please help me in guiding how to remove the displaying text "warning:javascript window" in the app.response window...

Thanks a lot

BalajiGurumurthy