If without Else what happens?
I'm currently learning Python and wonder what happens if I define an if in a for loop but no else
if the if condition is not met
the loop is then repeated as soon as the if is fulfilled or simply directly
Sorry for the beginner question, I started this week
for each pass is checked whether the condition for if is fulfilled
-if yes, first what is done in if and then what is done outside if but inside for loop
if no, only what is outside if but within loop is executed
A loop has several iterations (throughs) you define.
Let’s say you’re about the word “good question”.
There are 9 runs. What happens per pass in the loop does not interest the loop as long as you do not break angibst (or other statements that leave the so-called stack). This can also be an exception or, depending on the paradigm, the return or even an exit().
So you have to intervene in the condition and manipulate the current passage – whether with if, if-else, try-except, match-case…., completely irrelevant.
The rules are simple:
That as a prerequisite.
Thus, the For-Loop runs just as long as it is to run independently of the If-Statement. What happens in his block doesn’t matter to the For-Loop. And if the condition of the If applies, the If block is executed once. If not, the For-Loop will continue with the next iteration.
The code within the loop is executed in each passage.
The code within the conditional block is executed when the condition (within the respective passage) is fulfilled.
The loop does not care about the if, because it may be within the loop is just a query without action. Without specific code, you can’t say what happens, but a missing else doesn’t matter. Then there is no specified alternative to fulfilling the if condition.
You should find help that helps you learn basic knowledge at least.