#conditions with variable or function

12 messages · Page 1 of 1 (latest)

tulip reef
#

I know that if I have a function call as a condition it will run the function everytime the condition is checked but what if I had a variable with a function assigned to it and I put the variable in the condition, would it execute the function everytime the condition is checked? Or does it just execute once and keep the return value of the function

tall spindleBOT
#

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 use !howto ask.

spare sky
#

it will run the function everytime the condition is checked
not necessarily. it depends on said condition. short circuit may be kicking in (again, depends on said condition)

had a variable with a function assigned to it and I put the variable in the condition, would it execute the function everytime the condition is checked?
can you provide an example?

as a side note - do note that if said function can be evaluated at compile time, depends on your compiler optimization settings - the functions may not be called at all

smoky sable
#

would call foo() 10 times or not

#

and it wont

#

@tulip reef i guess that is what you asked?

#

idk what else could the question be directed at

#

you are copying the return value of the function into a variable

#

not aliasing the function

spare sky
#

🤷‍♂️
It would be beat to let them answer instead of guessing

mystic vault