# How to do a while loop with counter [closed]

I want to make this clean and shorter and I was wondering how I can do it? While loop would be best but how do i implement it?

if line.startswith('ACME'):
if counter == 2:
compname, value = line.split('(')
value = float(value[0:-14])
products[f'{compname}'] = value
if counter == 3:
compname, value = line.split('(')
value = float(value[0:-14])
products[f'{compname}'] = value
if counter == 4:
compname, value = line.split('(')
value = float(value[0:-14])
products[f'{compname}'] = value
if counter == 5:
compname, value = line.split('(')
value = float(value[0:-14])
products[f'{compname}'] = value


'''

• What's the purpose of the checks? They all look the same. It looks like you could just change the condition to if 2 <= counter <= 5:, then get rid of all but one of those bodies. – Carcigenicate Nov 21 at 23:18
• would belong to codereview site, but maybe would be downvoted there... I migrated it there, but maybe it wasn't the best choice. – Jean-François Fabre Nov 21 at 23:20
• Ya, I don't think this should have been migrated. It's more appropriate here, but I think it lacks context to be ontopic. – Carcigenicate Nov 21 at 23:22
• Why are you even using an if statement? The contents of each branch are identical. – TigerhawkT3 Nov 22 at 0:12
• This question as-is does not provide the required context and is thus off-topic for Code Review. It shouldn't have been migrated. – Mast Nov 22 at 8:04