0

I'm trying to conditionally check a variable and iterate through a while loop, but I've not been able to get it. Here is the snippet.

if(bla==""){
  //Processing something
} else {
  while(bla==""){
    //iterating variable 'bla' till it becomes ""(blank)
    //Processing something
  }
}

First I check if a variable bla is blank and then do the processing. Otherwise I iterate the variable bla until it becomes blank in the while condition, and then do the same processing.

How can it be done?

5
  • what errors are you running into? The code looks ok to me Commented Dec 13, 2017 at 5:21
  • 1
    Your code seems correct. What is not working with your solutiuon? Commented Dec 13, 2017 at 5:21
  • 1
    while(bla=="") will loop while it is an empty string, not until it becomes one. Commented Dec 13, 2017 at 5:22
  • if you want to loop until it becomes blank - the loop should be true until it becomes blank ... so while(bla!=="") Commented Dec 13, 2017 at 5:24
  • It goes into infinite loop if in the first run the variable bla is not blank Commented Dec 13, 2017 at 5:26

2 Answers 2

1

IF you want to iterate variable 'bla' till it becomes ""(blank) you need to put condition as while(bla != "")

if (bla == "") {
  //Processing something
} else {
  while (bla != "") {
    //iterating variable 'bla' till it becomes ""(blank)

  }
  //Processing something
}
Sign up to request clarification or add additional context in comments.

Comments

0

This may do the trick :

while(bla==""){
   //iterating variable 'bla' till it becomes ""(blank)
   //Processing something
}

if(bla === ""){
  //Processing something when bla is empty

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.