Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis5 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