How can I explain this while-loop?

I have an C++ source code and I have to convert it into C#. But in C++, there's a strange while loop that I can not understand.

1
2
3
while(m_get(&mr,&ml,&mx,&my),id){
   (while body)
}


m_get is a void function that return mouse in formation.
id is an unsigned short type.

Can you help me to explain this while loop.

Thank you,
Last edited on
I'm pretty sure that code is equivalent to
1
2
3
4
5
6
7
8
9
10
while (true)
{
    m_get(&mr, &ml, &mx, &my);
    if (id)
    {
        // (while body)
    }
    else
        break;
}

(You can write it a couple of different ways).

Basically, the line m_get(&mr,&ml,&mx,&my),id first does m_get(&mr,&ml,&mx,&my) and then returns the value of id.

There's a little explanation on the comma operator here:
http://www.cplusplus.com/doc/tutorial/operators/
(Just do a search for "Comma operator" on that page and you'll find it).
Thank you long double main!

I'll try this.
Topic archived. No new replies allowed.