In Python: I want to continue with something2 either if something true and something3 true or else:

if something:
    if something3:
        number += 1
        {continue on something2}
else:
    if something2:
        if 2 == 2:
            number += 2

Is this possible?

2 Answers

0
Petar Velev On

The program will continue no matter what.

imagine a function like.

def foo(condition)
    x = 0
    if condition:
       x = x + 1
    else:
       x = x + 2

    print x

No matter of the condition the print will be executed. Programs don't stop just because of if statement.

if statements are simple branching. You can execute one of the branches depending on a condition. If the if evaluates to true you'll enter the first branch and execute the code after the if statement. If the condition is false the code after the else will be executed.

Edit: due to OP comment

if something and something3 true or something false - continue

Then you should just think about your logic. You do not want to continue if something is true but something3 is not.

if something:
  if something3:
     add_something()
  else:
     # do not continue. maybe return here

# continue with your code
0
quamrana On

I think I would write it like this:

if something:
    if somethingElse:
        number += 1
        f()
else:
    f()

In two of the cases f() is called. It is only when something is true and somethingElse is not true does f() not get called.