1

I am using while loop to run the logic until both the int values are same.below is the code and compiler executes the while condition, it skips.

        while(paramCnt == threshold_value){
            ps.setString(paramCnt++, "abc");
        }

code is not working when paramCnt value is less than threshold_value. I want to run it until both values are equal.

I was not sure of where i am doing wrong. any help is appreciated.

2
  • 3
    If you want to "run it until both are equal", you need while (paramCnt != threshold_value). This runs it while both are equal. Commented Aug 15, 2018 at 6:30
  • 1
    Remove the java-ee tag from your post. The question has nothing to do with java-ee. Commented Aug 15, 2018 at 6:41

2 Answers 2

3

A while loop executes the code between it's brackets while a condition is true. Your condition is not true from the start. In order to loop until both values are equal you could change your condition to:

while(paramCnt != threshold_value){
    ...
}

Now you would be looping until paramCnt and threshold_value are equal.

Sign up to request clarification or add additional context in comments.

Comments

2

If you want to loop until they equal, it means keep looping if they don't equal:

while(paramCnt != threshold_value){
     ps.setString(paramCnt++, "abc");
}

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.