# Control loop problem

**URL:** <https://forum.codewithmosh.com/t/control-loop-problem/13698>\
**Category:** Java\
**Created:** [July 14, 2022, 11:35pm UTC](https://forum.codewithmosh.com/t/control-loop-problem/13698 "2022-07-14T23:35:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arun](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Arun](https://forum.codewithmosh.com/u/Arun)\
**Post date:** [July 14, 2022, 11:35pm UTC](https://forum.codewithmosh.com/t/control-loop-problem/13698/1 "2022-07-14T23:35:33Z")

</div>

public static void main(String args) {  
// TODO Auto-generated method stub  
int num;  
@SuppressWarnings(“resource”)  
Scanner scanner = new Scanner(System.in);  
System.out.print(“Please enter the number”);  
num = scanner.nextInt();  
if ((num \>= 10 ) && (num \<= 100 ))  
System.out.println(“SUCESS”);  
else;  
System.out.println(“PROBLEM”);   
}  
I came across this problem while doing something else. I f we enter a number less than 10 or greater than 100, we get “PROBLEM” displayed. But any number between 10 and 100 both “SUCCESS” and “PROBLEM” are displayed instead of only “SUCCESS”. Any idea what is wrong or am I missing something?

---

<div class="post-metadata">

**Author:** ![UniqueNospaceShort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/uniquenospaceshort/32/1814_2.png) [@UniqueNospaceShort](https://forum.codewithmosh.com/u/UniqueNospaceShort)\
**Post date:** [July 15, 2022, 8:10am UTC](https://forum.codewithmosh.com/t/control-loop-problem/13698/2 "2022-07-15T08:10:44Z")

</div>

Hello,  
Your problem lies here

`else;`

Remove the semi-colon.

Regards.

---

<div class="post-metadata">

**Author:** ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Post date:** [July 16, 2022, 3:54am UTC](https://forum.codewithmosh.com/t/control-loop-problem/13698/3 "2022-07-16T03:54:27Z")

</div>

This is one of the reasons the [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html#s4.1.1-braces-always-used) recommends always using brackets even when they are not required:

> Braces are used with `if`, `else`, `for`, `do` and `while` statements, even when the body is empty or contains only a single statement.

So your code should look like:

```java
if (num >= 10 && num <= 100) {
  System.out.println(“SUCESS”);
} else {
  System.out.println(“PROBLEM”);
}

```
