If the while loop condition is page dependent use
while (_condition(booleanExpression)){...}
Eg
while (document.loginForm.userName != "karthik"){
// some statements
}
should be written as
while (_condition(document.loginForm.userName != "karthik")){
// some statements
}
You do not need to add _condition if the condition is not dependent an the page DOM.