6 Respostas
+ 4
â€âąâ đđąđąđđš đđĄđđČđđ„ ââąâ€ no, without the negation it would be the equivalent of a do-until loop, implemented in visual basic and perl afaik. This variant maybe is a better semantic equivalent to do-while:
while True:
# some code
if ăconditionă:
continue
else:
break
If the condition holds, we continue iteration, else (=if ăconditionă is false) we break
+ 6
The best equivalent imo is to use while loop with break. Note that the condition is negated.
Cpp example:
do
{
// some code
} while ăconditionă;
Python equvalent:
while True:
# some code
if not ăconditionă:
break
+ 5
If the 'if' statement is the last one in the loop, the "continue" would be redundant.
+ 2
python has a while loop not do while
+ 2
I know Sonic, it was just to show the equivalence in another way and emphasize the need for the condition to be false in order to break