简体   繁体   中英

The while Loop problems [on hold]

The error of my code which cause the while loop to be executed infinitely. Anyone can find which error I get wrong? Thanks.

 int count = 0;
 while(count < 10 || true){
     System.out.print(count+"\t");
 }

The condition on that loop is that it will execute while count < 10 is true OR while true is true. True is always true, so the loop will always execute.

Also, in a while loop count doesn't increment itself in every iteration of the loop, like in a for loop. So, count will always be lower than 10.

Why did you add that true condition on the loop? Seems like you were trying to achieve something.

There are two errors in the code.

  1. Always true condition

    while (count < 10 || true) -> Which will be true always.
  2. Count is not incremented in the loop.

Question is not clear, please edit with additional details what you are trying to achieve.

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