简体   繁体   中英

java while loop not working as expected

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.

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.

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");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM