Question: 1. Can `System.exit()` be used at sentinel value?
2. If not what purpose would `System.exit()` provide?
3. If this code is in a loop and is entered, would it exit?

```
 String day;
 day = JOptionPane.showInputDialog("what is todays date");
 JOptionPane.showMessageDialog(null,"Today is: " + day);
 System.exit(1);

```

Answer: 
> 
> 1.Can system.exit() be used at sentinel value? 
> 
> 
> 

Why would you want to use it as sentinel values? You probably can't use it as a loop guard in your loop, because once exited, your program terminates.

Secondly, if there is any unfinished task, your program will terminate abruptly.

> 
> If not what purpose would 2.system.exit() provide?
> 
> 
> 

You may look at this post regarding Java's System.exit(): [Java's System.exit(0); vs C++ return 0;](https://stackoverflow.com/questions/24401621/javas-system-exit0-vs-c-return-0)

> 
> 3.if this code is in a loop and they enter 1. Would it exit?
> 
> 
> 

Your code will exit eventually no matter what is being entered. It will not only exit the loop, it will terminate your program. To jump out of a loop, you use `break` and not `System.exit()`.

To skip the rest of code in a loop, you use `continue`.
Any flow should never be derived from System.exit() . 

you have various other mode exit from a program

return , continue , break or even u can throw logical exception which also let you know the state of program.