❔ Understanding guidelines around use of 'bool'
Hi folks, i need help understanding the usage of bool before a loop. I've looked at the way some people write their code, sometimes bool is made equals to true and sometimes false. Are there certain guidelines for this?
7 Replies
It entirely depends on what you are doing in the loop and what that bool is for
In this code, for example, could you explain why bool is made false initially?
In that specific case it doesn't matter, and you can even leave out the
= false
, because it immediately gets replaced unconditionally in the isParsable = ...
line at the start of the loop
They probably set it to false
because they use !isParsable
in the while
part, so they're making absolutely sure it always runs once (although the do ... while
already does that)
They probably wanted it to not be affected if that do ... while
was converted to a while
Ah I see! If lets say i initialize a bool but leave it undefined and then use it in a loop, would bool = true or bool = false let me leave the loop?
Which "leaves the loop" is entirely dependent on how you write the condition inside the
while(...)
Also not all while loops will even use a bool variableAh okay, got it thanks sir! 🫡
Also i'd just started learning modular programming but am kinda struggling to wrap my head around the concepts. Are there any online resources youd recommend? 🙂
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.