6 Respuestas
+ 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