In a Bash script, how can I exit the entire script if a certain condition occurs?
In a Bash script, how can I exit the entire script if a certain condition occurs?
In a Bash script, how can I exit the entire script if a certain condition occurs?
Use break: while (true) { …. if (obj == null) { break; } …. } However, if your code looks exactly like you have specified you can use a normal while loop and change the condition to obj != null: while (obj != null) { …. }