#trying to come up with an algorithm for a foor loop
7 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
that means your condition is
i < std::min(bruh, 8)
oh wait, this is C, so I guess you can do
int limit = bruh < 8 ? bruh : 8;
// ...
i < limit
anyhow, it just means you're taking the lower of the two values and using that as the limit
would you be able to elaborate a bit on what that syntax means?
The conditional operator, (colloquially called ternary operator) of the form Condition ? T : F evaluates T if the Condition is true, otherwise F.
The result of the whole expression is either the expression T or F. This also means that T and F must have compatible types.
A classic use case for the conditional operator is the min function.
int min(int a, int b) {
return a < b ? a : b;
}
This function chooses a if a is lower than b, or b otherwise.
- more concise code
- makes it easier to be
const-correct
- can be hard to read, especially when nested and formatted poorly