What's the difference between num=+10 and num+=10?

assignment-operator, java

Solution

`num=+10` is equivalent to `num=10`. That's why the loop never ended.

`num+=10` is equivalent to `num=num+10`, which gives you the desired behavior.

Problem

I am new to java, so while experimenting (which is, as you know, the best way to learn), I tried the following code: ``` public class wHilE{ public static void main(String[] args){ int num = 10; while(num<=100){ System.out.println("while countdown = "+ num); num=+10; } } } ``` It results is an infinite loop printing `while countdown = 10`, but when I change `num=+10` to `num+=10` I get the desired result. Why is it so?

Original source

Related problems