# What's wrong with this program?

**URL:** <https://forum.codewithmosh.com/t/whats-wrong-with-this-program/13004>\
**Category:** Java\
**Created:** [June 12, 2022, 5:25am UTC](https://forum.codewithmosh.com/t/whats-wrong-with-this-program/13004 "2022-06-12T05:25:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Waqar](https://avatars.discourse-cdn.com/v4/letter/w/7993a0/32.png) [@Waqar](https://forum.codewithmosh.com/u/Waqar)\
**Post date:** [June 12, 2022, 5:25am UTC](https://forum.codewithmosh.com/t/whats-wrong-with-this-program/13004/1 "2022-06-12T05:25:51Z")

</div>

I can’t understand what’s wrong with this program. It’s not stopping at i\<=number

public class AddNumbers {

```
public static void main(String[] args) {
	// TODO Auto-generated method stub
	
	int number = 10;
	for (int i = 1; i <= number; ++i) {
		number +=i;
	}

	System.out.println(number);
	
}

```

}

---

<div class="post-metadata">

**Author:** ![eelsholz](https://avatars.discourse-cdn.com/v4/letter/e/439d5e/32.png) [@eelsholz](https://forum.codewithmosh.com/u/eelsholz)\
**Post date:** [June 12, 2022, 11:52pm UTC](https://forum.codewithmosh.com/t/whats-wrong-with-this-program/13004/2 "2022-06-12T23:52:42Z")

</div>

Try adding some logging inside your loop and I think you’ll see what’s going on.

```java
System.out.println("i");
System.out.println(i);
System.out.println("number");
System.out.println(number);

```

---

<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:** [June 13, 2022, 9:12pm UTC](https://forum.codewithmosh.com/t/whats-wrong-with-this-program/13004/3 "2022-06-13T21:12:30Z")

</div>

Hi,  
The condition to get out of the loop is `i <= number`.

Every loop increment `i` by 1.  
Every loop increment `number` by `i`.  
So basically `number` grows faster than `i`.  
You’ll never meet the condition to exit the loop.  
Regards.

EDIT: I did a [fiddle](http://tpcg.io/_3K9ZAV) to check and in practice it stops at some time probably because of the type boundaries.
