I made this piec of code and it works just fine for the following:
Write the code to check whether a string given through input()contains only valid characters, but stop once you reach one invalid character. So if the string is valid print valid string. If the string is invalid print invalid string till that point.
But now i have to use a while loop for this and i can't get it done, can you guys help me or explain to me how convert this code to a while loop, while maintaining the exact same function.
file = input()
invalid_letter_found = False
correct_letters = []
for current_letter in file:
    if current_letter in ['A', 'T', 'G', 'C']:
        correct_letters.append(current_letter)
        continue
    elif current_letter != ['A', 'T', 'G', 'C']:
        invalid_letter_found = True
        break
if invalid_letter_found == True:
    print(f'invalid {"".join(correct_letters)}')
else:
    print(f'valid {"".join(correct_letters)}')