Why can I do this:
return (tarea->ini == NULL) && (tarea->fin == NULL); // no hay parentesis global
but not
while (tarea->ini != NULL) && (tarea->ini != kol) // no hay parentesis global
?
since it tells me that I should put the while like this:
while ((tarea->ini != NULL) && (tarea->ini != kol)) // parentesis global
I want to know why it is not going to be something that that return is verifying only the first condition...
The short answer is: because while expects an expression in parentheses and return does not.
Parentheses can be used to separate or group expressions of any type (arithmetic, conditional, etc.) in the same statement, as in the case of the return statement .
On the other hand, while , like the other control structures (if, for, switch, etc.) requires that one or more conditional expressions be specified in parentheses.
Ultimately, the "global" parentheses you use in a while statement don't mean the same thing as the ones you're using in the return statement .
It is not that there is a revealing reason per se (at least as far as I know), it is simply that the syntax of both is defined in such a way.
The while is a conditional structure that requires a condition in parentheses to work:
The return is a statement that does not have parentheses in its syntax:
What it does require is a character to separate the return keyword from what comes next, it doesn't necessarily have to be separated by a space, really any character that can't be used in an identifier because then when "returnvalue" is put together the compiler would take the whole word as an identifier.
Then the valid characters to separate return from what comes are all those that are not letters, numbers or underscores, for example:
In any of the previous cases it is valid to say that the whole expression is evaluated (that is, omitting the fact that there are short-circuit operations) so there is no difference between using or not using parentheses.
In the case of the return, what happens is that it is doing an operation and at the end it can be true or false
In this other case of while the syntax asks you to be
If you put it in the following way, it does not know what the operation is that you are trying to evaluate, that is why it must go inside the parentheses.