Answer the question
In order to leave comments, you need to log in
Why do most programming languages allow assignment in a condition?
This increases the number of errors and reduces the readability of the code. In what cases can such an assignment be useful?
Answer the question
In order to leave comments, you need to log in
char c;
while ((c = getchar()) != EOF) {
// do something
}
They operate with constructions and expressions. The expression is all that matters, and that's the reason expressions can be used in conditions. They can also be used in conjunction with the return statement - that doesn't bother anyone, does it? What about the expressions in the for condition? Therefore, expressions in conditions should not be embarrassing, all the more so because sometimes it is very beautiful.
This is useful when you need to get a value from a function or method for a condition, and then apply it multiple times inside an expression in the condition:if(a=getA()&&a>b){...}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question