How to use CONTINUE and BREAK statement within a loop in Python?
DATA MUNGING DATA CLEANING PYTHON MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

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

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.

Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

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.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

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

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.

Walmart Sales Forecasting Data Science Project
Data Science Project in R-Predict the sales for each department using historical markdown data from the Walmart dataset containing data of 45 Walmart stores.

Loan Eligibility Prediction using Gradient Boosting Classifier
This data science in python project predicts if a loan should be given to an applicant or not. We predict if the customer is eligible for loan based on several factors like credit score and past history.