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")

23rd Jun 2020, 7:21 PM
Ajisegiri Sunday
Ajisegiri Sunday - avatar
6 Antworten
+ 4
I think you wanted continue not break.
23rd Jun 2020, 7:43 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
I want the admin greetings to be different from others and thanks it's continue not break
23rd Jun 2020, 8:13 PM
Ajisegiri Sunday
Ajisegiri Sunday - avatar
+ 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...
23rd Jun 2020, 7:25 PM
Slick
Slick - avatar
0
Thanks i sliced the list already but is there a way I can use a break statement to get same result?
23rd Jun 2020, 7:37 PM
Ajisegiri Sunday
Ajisegiri Sunday - avatar
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
23rd Jun 2020, 7:41 PM
Slick
Slick - avatar