Python- The Loops

The while loop 

To test the while loop copy the code as below:

lv_counter = 0
while (lv_counter < 10):
print(“The counter value is: “,lv_counter)
lv_counter = lv_counter + 1

 

Make sure to ident the block as shown below

 

Once you run the program, you should get the output as shown below

The for loop

You can iterate over a range of number or strings or lists.

for number in range(1,10):
print (“Current number is : “,number)

for letter in ‘Tutorial’:
print(“Current letter is :”,letter)

places = [‘Dhaka’,’Islamabad’,’Thimpu’,’New Delhi’]
for place in places:
print(“You are in this city now :”,place)

In the same file created above, add the above lines as shown below”:

 

Once you’ve run the program, you should see the output as shown below:

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s