How to use CONTINUE and BREAK statement within a loop in Python?
DATA MUNGING

How to use CONTINUE and BREAK statement within a loop in Python?

How to use CONTINUE and BREAK statement within a loop in Python?

This recipe helps you use CONTINUE and BREAK statement within a loop in Python

0
In [1]:
## How to use CONTINUE and BREAK statement within a loop in Python
def Kickstarter_Example_52():
    print()
    print(format('How to use CONTINUE and BREAK statement within a loop in Python',
                 '*^82'))
    import warnings
    warnings.filterwarnings("ignore")

    # Import the random module
    import random
    # Create a while loop # set "running" to true
    running = True
    # while running is true
    while running:
        # Create a random integer between 0 and 5
        s = random.randint(0,5)
        # If the integer is less than 3
        if s < 3:
            print(s, ': It is too small, starting again.')
            continue
        # If the integer is 4
        if s == 4:
            running = False
            print('It is 4! Changing running to false')
        # If the integer is 5,
        if s == 5:
            print('It is 5! Breaking Loop!')
            break
Kickstarter_Example_52()
*********How to use CONTINUE and BREAK statement within a loop in Python**********
0 : It is too small, starting again.
0 : It is too small, starting again.
It is 4! Changing running to false

Relevant Projects

Human Activity Recognition Using Smartphones Data Set
In this deep learning project, you will build a classification system where to precisely identify human fitness activities.

Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

Predict Macro Economic Trends using Kaggle Financial Dataset
In this machine learning project, you will uncover the predictive value in an uncertain world by using various artificial intelligence, machine learning, advanced regression and feature transformation techniques.

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

Music Recommendation System Project using Python and R
Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Zillow’s Home Value Prediction (Zestimate)
Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.