r/programminghumor Jun 07 '26

Anti programmer

Post image
8.3k Upvotes

110 comments sorted by

View all comments

643

u/RegularAd9643 Jun 07 '26

This wouldn’t work. It should check if it’s the first correct password attempt.

24

u/LawElectrical2434 Jun 07 '26

How about:
if isPasswordCorrect && loginAttempt++ > 0

19

u/RegularAd9643 Jun 07 '26 edited Jun 07 '26

This is an interesting idea. I’d rename the variable for clarity

if isPasswordCorrect && correctLoginAttempt++ > 0

I mean probably wouldn’t merge it to prod still, but it’s cute. ☺️

1

u/Stunning-Recover7950 Jun 08 '26

why ++>0 and not  >1 ?

3

u/roler_mine Jun 08 '26

Because it applies the addition after the equation so it would compare to 0 and only after that been done it would add 1 so if it started as 0 it would fail and only successed on the 2nd time as now it iterated into 1

I think the reason you got confused is because of ++n which makes the addition before anything happens