+ 1

For loops and Continue

Can anyone give me tips on why this doesn't have any output. This is in Python. Am I missing something? letter = 1 for w in 'Akeno Himejima': if w == 'H': continue print('A is not to be processed ') print('Letter ', letter, 'is ', w) w+=1

1st Dec 2018, 1:53 AM
Rene
Rene - avatar
5 Answers
+ 5
Yes you are. :) Code after continue won't execute. Either indent it differently or change the logic of your code. Of course, notice that you are adding 1 to the variable that is not a counter... num = 1 for w in 'Akeno Himejima': if w == 'H': continue print('A is not to be processed ') print('Letter', num, 'is', w) num += 1 https://www.programiz.com/JUMP_LINK__&&__python__&&__JUMP_LINK-programming/break-continue
1st Dec 2018, 3:47 AM
dρlÏ…Ń•ÏlÏ…Ń•
dρlÏ…Ń•ÏlÏ…Ń• - avatar
+ 5
What are you trying to achieve with your code? I'm having problems understanding what you are trying to do here. Everything after the continue will not be processed because it iterates the loop immediately. So everything below it will be skipped.
1st Dec 2018, 2:13 AM
Lambda_Driver
Lambda_Driver - avatar
1st Dec 2018, 2:28 AM
Diego
Diego - avatar
+ 4
dρlÏ…Ń•ÏlÏ…Ń• and the first print put before continue, and change A to H
1st Dec 2018, 5:53 AM
Gordon
Gordon - avatar
+ 1
thanks so much
1st Dec 2018, 7:30 PM
Rene
Rene - avatar