Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

CONDITIONING AND LOOPING

CONDITIONING LOOPING

At the heart of every if statement is an expression that can be The looping statement is used to repeat the execution of statements
evaluated as True or False and is called a conditional test. Python repeatedly according to the desired iteration. In python, there are two
uses the values True and False to decide whether the code in an if kinds of loop:
statement should be executed. In Python to perform a condition
check, there are four kinds of statements. Among others: 1) While Loop statement
2) For Loop statement

1) IF STATEMENT
If statement is used for selecting where if the condition is true
then the program will execute the statement below. In python, for the
writing of conditioning and statements separated by a colon (:).  
The general form of the if statement:

BREAK, CONTINUE, AND PASS


COMMAND
2) IF - ELSE STATEMENT
1) BREAK
The if-else statement is used to select the condition where if the
The break command is used to stop the iteration process from the for
condition is true then the program will execute the statement 1.
or while statement. The statement under the break will not be executed
However, if the value of the condition is false  the second statement
and the program will exit the loop process.
will be executed.

2) CONTINUE

Continue command causes the program how to return to the looping


command. So, if in a loop there is a continue statement, then the program
will return to the looping command for the next iteration.

3) IF - ELIF - ELSE STATEMENT


3) PASS
The if - else - elif statement is used to select the conditions where
Pass Statement command causes the program to take no action.
conditions are given more than 1 condition or have some conditions.
If the first condition is true then do the selection of second condition
and so on.

4) NESTED-IF STATEMENT

Nested condition is a condition inside the certain conditions, If


there are 2 branch conditions then in one branch of the condition can
also be in the contents of a certain condition.

REFERENSI
Matthes, E. (2015). Python Crash
Course . San Francisco: William
Pollock.

You might also like