not working while-loop
i=0
l1=["rohan","sachin","sam","raj"]
while i<len(l1):
if l1[i].startswith('s'): #if i comment out this line it is working
print("GREET "+l1[i])
i=i+1
not working while-loop
i=0
l1=["rohan","sachin","sam","raj"]
while i<len(l1):
if l1[i].startswith('s'): #if i comment out this line it is working
print("GREET "+l1[i])
i=i+1
That is because incrementing of i is done inside if condition instead of while loop. As first word in your list did not start with "S" it wont go inside if hence i is not incremented and while loop executes forever. it is just a logic issue
Indentation is important in Python.
You must increment your counter i
every time, not just when you print, otherwise it's an endless loop.
i=0
l1=["rohan","sachin","sam","raj"]
while i<len(l1):
if l1[i].startswith('s'):
print("GREET "+l1[i])
i=i+1 # <- increment counter outside of if-block!
yes ,after shifting counter to left it is working. counter should be placed out side of if block.