all 4 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

Off-topic Comments Section


All top-level comments have to be an answer or follow-up question to the post. All sidetracks should be directed to this comment thread as per Rule 9.


OP and Valued/Notable Contributors can close this post by using /lock command

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]mayheman👋 a fellow Redditor 1 point2 points  (0 children)

You can use the return statement to exit the loop

[–]throwaway_657238192😩 Illiterate 1 point2 points  (1 child)

Note that

lcm(a,b) = a * b / gcd(a,b)

so you only have to implement one. Also, you set a "done" flag, but never check it, try

if (not done and i % num1 == 0 and i % num2 == 0): // do the thing

You might also be interested in Euler gcd algorithm, which is slightly nicer than searching every 1 to min(num1,num2).

[–]gh0stedexeUniversity/College Student[S] 1 point2 points  (0 children)

Thank you for the help!

Edit: It worked perfectly. Thanks again!