We use the if/else statements to help us declare and specify something. We use if to execute if the condition is true. If the expression is true the body of the if statement is executed, if it’s false the statement present after the if statement is executed. In either case, any line of code present outside if the statement is evaluated by default. An example is, a=10, if a>40;
print (this is the if body)
print (this is outside the if block)
Since 10 is not greater than 40, the statement present inside the if block will not execute. Instead, the statement present outside the if block is executed.
We could specify the statements that will be executed if a condition is true. If you want to evaluate statements that determine whether a condition is actual and if a separate set of statements is false, you can use the if-else conditional statement.
Leave a Reply
You must be logged in to post a comment.