can't make a cycle properly
i want to make a cycle that counts the number of loops the program does but it's just infinitely counts numbers from 0 by some reason
15 Replies
Did you mean to do
count != 1
instead of num != 1
?
What this code will do is get a long num
, then run that loop forever unless num
is 1.
However you don't update num
inside the loopit's the Collatz conjecture
you want to count how many steps it took to get to 1, right?
exactly
the inner loop will run until the number reaches 1, then the outer loop should immediately break after that? because num == 1, count will always be 1
i think you want a counter variable inside the while loop
at the start of the loop, you just increase it by 1, no need for two loops
OH
it runs infinitely because you did a semicolon after the for parantheses
yeah but it still doesn't do what i
yes, because you don't actually need the for loop
this will basically just increase count after one whole process of doing the Collatz conjecture on a number. to count the steps, you want to count inside the while loop
like this?
yes
and it infinitely counting again
how does your code look now?
ohh
try this
still
nvm fixed
@hengi tysm