I am taking some C# tests online and I came across the following code:
using System;
namespace ProgrammingExercise
{
class FindOutput
{
static void Main(string[] args)
{
int num= 1234, r;
while (num > 0)
{
r = num % 10;
num = num / 10;
Console.WriteLine(+r);
}
}
}
}
I am a bit confused about the first line inside Main(). Does it mean that num=1234=r? I also don't understand why it's written +r... what does it do?
Edit
After the comments, it makes more sense and I'm writing the way I think it works:
- while evaluates to true (1234>0)
- r = 1234 % 10 = 4
- num = 1234 / 10 = 123 (can't result 123.4 because num is an int)
- 4 is printed ... the execution continues till the condition evaluates to false.