Teachnique
      CourseRoadmaps
      Login

      OverviewCommentsUser InputNumbersBooleansHistoryHello World ProgramEnvironment SetupSyntaxVariablesData TypesType CastingUnicode SystemLiteralsOperators

      Control FlowBreak StatementContinue StatementPass StatementNested LoopsDecision MakingIf StatementIf-else StatementNested IF StatementMatch-Case StatementLoopsFor LoopsFor-else LoopsWhile Loops

      FunctionsBuilt-in FunctionsDefault ArgumentsKeyword ArgumentsKeyword-Only ArgumentsPositional ArgumentsPositional-Only ArgumentsArbitrary ArgumentsVariable ScopeFunction AnnotationsModules

      StringSlicing StringsModify StringsString ConcatenationString FormattingEscape CharactersString MethodsString Exercises

      ListsList ExercisesAccess List ItemsChange List ItemsAdd List ItemsRemove List ItemsLoop ListsList ComprehensionSort ListsCopy ListsJoin ListsList Methods

      TuplesAccess Tuple ItemsUpdate TuplesUnpack Tuple ItemsLoop TuplesJoin TuplesTuple MethodsTuple Exercises

      SetsAccess Set ItemsAdd Set ItemsRemove Set ItemsLoop SetsJoin SetsCopy SetsSet OperatorsSet MethodsSet Exercises

      DictionariesDictionary ExercisesAccess Dictionary ItemsChange Dictionary ItemsAdd Dictionary ItemsRemove Dictionary ItemsDictionary View ObjectsLoop DictionariesCopy DictionariesNested DictionariesDictionary Methods

      ArraysAccess Array ItemsAdd Array ItemsRemove Array ItemsLoop ArraysCopy ArraysReverse ArraysSort ArraysJoin ArraysArray MethodsArray Exercises

      File HandlingWrite to FileRead FilesRenaming and Deleting FilesDirectoriesFile Methods

      OOP ConceptsDynamic BindingDynamic TypingAbstractionObject and ClassesEncapsulationInterfacesPackagesInner ClassesAnonymous Class and ObjectsSingleton ClassWrapper ClassesEnumsReflectionClass AttributesClass MethodsStatic MethodsConstructorsAccess ModifiersInheritancePolymorphismMethod OverridingMethod Overloading

      Feedback

      Submit request if you have any questions.

      Course
      Continue Statement

      Python Tutorial

      This Python tutorial has been written for the beginners to help them understand the basic to advanced concepts of Python Programming Language. After completing this tutorial, you will find yourself at a great level of expertise in Python, from where you can take yourself to the next levels to become a world class Software Engineer.

      Continue Statement

      Python Continue Statement

      Python continue statement is used to skip the execution of the program block and returns the control to the beginning of the current loop to start the next iteration. When encountered, the loop starts next iteration without executing the remaining statements in the current iteration.
      The continue statement can be used in both while and for loops.

      Syntax

      continue

      Flow Diagram

      The flow diagram of the continue statement looks like this
      
      The continue statement is just the opposite to that of break. It skips the remaining statements in the current loop and starts the next iteration.

      Example 1

      Now let's take an example to understand how the continue statement works in Python
      for letter in 'Python': # First Example
      if letter == 'h':
      continue
      print ('Current Letter :', letter)
      var = 10 # Second Example
      while var > 0:
      var = var -1
      if var == 5:
      continue
      print ('Current variable value :', var)
      print ("Good bye!")
      When the above code is executed, it produces the following output
      Current Letter : P
      Current Letter : y
      Current Letter : t
      Current Letter : o
      Current Letter : n
      Current variable value : 9
      Current variable value : 8
      Current variable value : 7
      Current variable value : 6
      Current variable value : 4
      Current variable value : 3
      Current variable value : 2
      Current variable value : 1
      Current variable value : 0
      Good bye!

      Checking Prime Factors

      Following code uses continue to find the prime factors of a given number. To find prime factors, we need to successively divide the given number starting with 2, increment the divisior and continue the same process till the input reduces to 1.
      The algorithm for finding prime factors is as follows −
      1. Accept input from user (n)
      1. Set divisor (d) to 2
      1. Perform following till n>1
      1. Check if given number (n) is divisible by divisor (d).
      1. If n%d==0
      1. a. Print d as a factor
      1. Set new value of n as n/d
      1. Repeat from 4
      1. If not
      1. Increment d by 1
      1. Repeat from 3
      Given below is the Python code for the purpose
      num = 60
      print ("Prime factors for: ", num)
      d=2
      while num > 1:
      if num%d==0:
      print (d)
      num=num/d
      continue
      d=d+1
      On executing, this code will produce the following output
      Prime factors for: 60
      2
      2
      3
      5
      Assign different value (say 75) to num in the above program and test the result for its prime factors.
      Prime factors for: 75
      3
      5
      5

      Practice with Online Editor

      Note: This Python online Editor is a Python interpreter written in Rust, RustPython may not fully support all Python standard libraries and third-party libraries yet.
      Remember to save code(Ctrl + S Or Command + S) before run it.