0
Help in break statement
greeting=["admin","Shola","Taylor","Collins","peter"] print(greeting[0] + " can i show you the full report sir?") for element in greeting: if element == "admin": break print(element+ " welcome")
6 ответов
+ 4
I think you wanted continue not break.
+ 2
I want the admin greetings to be different from others and thanks it's continue not break
+ 1
Did you want to print all the names + welcome and then break when it gets to admin?
Put 'admin' last in the list
If you need it first use index slicing on the list:
...
for element in greeting[1:]:
print(element + 'welcome.')
But then you won't need the break...
0
Thanks i sliced the list already but is there a way I can use a break statement to get same result?
0
More slicing...
#all your other code
greeting = gretting[1:] + greeting[0]
for element in greeting:
if element == 'admin':
break
else:
................
But why? Theres really no point in breaking because the for loop will stop on its own