Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Repeating a block of code
#3
what you are looking for is loop
there are different code constructs, but based on your example, one very simple solution would be for-loop:

for i in range(10):
    print('something') # the body of the loop can be anything you want
this is simple loop, and the body will be executed 10 times. if you need you can use the control variable i in the body of the loop.

in other cases you can use while-loop
Reply


Messages In This Thread
Repeating a block of code - by owdcoder - Jun-11-2017, 02:52 PM
RE: Repeating a block of code - by Bass - Jun-11-2017, 02:58 PM
RE: Repeating a block of code - by buran - Jun-11-2017, 03:03 PM
RE: Repeating a block of code - by owdcoder - Jun-11-2017, 03:57 PM
RE: Repeating a block of code - by wavic - Jun-11-2017, 05:36 PM
RE: Repeating a block of code - by Bass - Jun-11-2017, 05:48 PM
RE: Repeating a block of code - by Larz60+ - Jun-11-2017, 07:27 PM
RE: Repeating a block of code - by RodNintendeaux - Jun-12-2017, 12:01 AM
RE: Repeating a block of code - by nilamo - Jul-14-2017, 03:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is 2/3 not just .666 repeating? DocFro 4 848 Dec-12-2023, 09:09 AM
Last Post: buran
  python multiple try except block in my code -- can we shorten code mg24 10 6,757 Nov-10-2022, 12:48 PM
Last Post: DeaD_EyE
  repeating a user_input astral_travel 17 2,567 Oct-26-2022, 04:15 PM
Last Post: astral_travel
  if else repeating Frankduc 12 2,816 Jul-14-2022, 12:40 PM
Last Post: Frankduc
  "If Len(Word) == 0" Code Block in Pig Latin Program new_coder_231013 3 2,198 Jan-02-2022, 06:03 PM
Last Post: deanhystad
  Try,Except,Else to check that user has entered either y or n (Code block pasted) RandomNameGenerator 3 2,420 Jun-29-2021, 08:21 PM
Last Post: RandomNameGenerator
  Repeating lines of code by an input Josh_Albanos 3 2,522 Oct-15-2020, 01:04 AM
Last Post: deanhystad
  factorial, repeating Aldiyar 4 2,928 Sep-01-2020, 05:22 PM
Last Post: DPaul
  Block of code, scope of variables and surprising exception arbiel 8 3,597 Apr-06-2020, 07:57 PM
Last Post: arbiel
  zlib decompress error: invalid code lengths set / invalid block type DreamingInsanity 0 7,043 Mar-29-2020, 12:44 PM
Last Post: DreamingInsanity

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020