My previous question
name = 'Jesaa29 Roy'
size = len(name)
print(size)
i = 1
while i < size:
if name[i].isspace():
i += 1
continue
print(name[i], end='')
i += 1
The point in this question was how continue
is working here.
HERES NEW QUESTION
name = 'Jesaa29 Roy'
size = len(name)
print(size)
i = -1
while i < size:
i = i +1
if name[i].isspace():
continue
print(name[i], end='')
I thought it will be better to do “pre increment” rather than “post increment” like in my previous code
But I’m getting ‘string index out of range’
Edit: Ig I got the answer say if I’m right or wrong.
The condition will increase i
till i
is smaller than size
Size is length of Jessa29 Roy
and is 11
Condition is while the i
is smaller than size
so when i
is 10 the condition is still met and i
is increased to 11
The next come printing with index and since indexing starts with 0 the last index is 10
i
is increased to 11 so it says ‘string index out of range’
while i < size - 1
should solve the problem