> command, command != "END") {...} Here, in the whi...">

What is the use of "," during a C ++ cycle?

string command;
string bookName;
while (cin >> command, command != "END")
{...}

Here, in the while state, there is a comma. I know that with &&or ||you can add several conditions.

But why use it ,?

Are there any specific benefits? Could you explain the usage and syntax?

+4
source share
1 answer

This is the comma operator, also known as the evaluate and forget operator. Effect a, b:

  • Evaluate a, including any side effects
  • Discard its value (i.e. do nothing with it)
  • Estimate b
  • Use the result bas the result of the whole expressiona, b

:

command cin, , command "END"

&& , , cin >> command (.. , END). , , (, , , command END), && ( ).

+19

Source: https://habr.com/ru/post/1680694/


All Articles