+ 1

I want to ask if there is a set of string is there like words=["Hi","Hello","Bye","See u"]and I want to print upto "Bye" then how can I do it using for loop

1st Dec 2016, 7:48 PM
Srinu
Srinu - avatar
6 Antworten
+ 3
for(int i=0;I<=words.length;i++){ if(words[i]=="Bye") { break; }}
13th Dec 2016, 5:09 PM
Sagar Mamidala
Sagar Mamidala - avatar
+ 1
"I want to ask if there is a set of string" A specific word or literal list of words? This is how you would ask if a specific value existed. if "string" in words: "I want to print upto "Bye"" for item in words: if word[item] == "bye": break else: print(item)
1st Dec 2016, 8:33 PM
Sapphire
+ 1
I will tell u later because I want a time to write a code ok
13th Dec 2016, 3:28 PM
Santosh Dussa
Santosh Dussa - avatar
0
at the risk of appearing naive, why not directly do it? why do you want the for loop? it would help to answer if we knew what other branches you need to tackle.
1st Dec 2016, 7:54 PM
Goutam Rudra
Goutam Rudra - avatar
0
You don't need a for loop in order to do that: // as list print words[0:3] output: ['Hi', 'Hello', 'Bye'] —————————————— // as plain ' '.join(words[0:3]) output: Hi Hello Bye
1st Dec 2016, 9:41 PM
Nedim Kanat
Nedim Kanat - avatar
0
for e in words: print(e) if e=="bye": break
25th Jan 2017, 7:20 AM
Amina Ben Salem
Amina Ben Salem - avatar