#Help me understand why this loop is not working?

1 messages · Page 1 of 1 (latest)

fast shadow
#

Basically there is a compiling error it doesn't increment i to 9, 10, 11... etc.

rocky pecanBOT
#

<@&987246399047479336> please have a look, thanks.

rocky pecanBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

To help you understand why the loop is not working, please provide the code snippet that you are referring to.

#

It depends on the context and requirements of the situation. If you are asked to send or share code, it is common to send it in text form. This can be done by copying and pasting the code into a text file or using a code-sharing platform or service. However, if you are working with a specific development environment or tool, there may be other methods for sharing code, such as sending project files or using version control systems.

#

There could be several reasons why a for loop is not incrementing:

  1. Incorrect initialization: The loop may not be initialized properly, resulting in the loop variable not being set to the desired starting value.

  2. Incorrect condition: The condition of the loop may not be set correctly, causing the loop to terminate prematurely or not execute at all.

  3. Missing or incorrect increment statement: The increment statement within the loop may be missing or written incorrectly, preventing the loop variable from being incremented.

  4. Infinite loop: If there is an error in the loop logic, it is possible that the loop is stuck in an infinite loop, where it keeps executing without ever reaching the termination condition.

  5. External interference: There might be external factors affecting the execution of the for loop, such as other code modifying variables used in the loop or unexpected input causing unintended behavior.

  6. Syntax errors: Syntax errors in the for loop declaration or any other part of the code can prevent proper execution and result in no incrementation.

  7. Loop variable modification within the loop: If there are statements within the for loop that modify the value of the loop variable directly, it can interfere with its expected incrementation.

To identify and resolve these issues, it is important to carefully review and debug your code, checking each component of the for loop and ensuring that it functions as intended.

pliant valley
fast shadow
#

i think it's an infinite loop once i is 8

#

but i don't know why

pliant valley
fast shadow
#

because my code prints out every increment and it doesn't print out 9, and i did something like if i=9, print out "hi" and it didn't print out hi

pliant valley
#

can you show your class implementation used in the scores array pls

fast shadow
#

what is that ;-;

pliant valley
#

you have an array scores

#

which type is it storing?

fast shadow
#

ohhh

#

u wanna see my score class?

pliant valley
#

yeah

fast shadow
#

it's a superclass for scores

pliant valley
#

problem is probably in the isUsed or Calculate method

#

also you got any error>

fast shadow
#

and i have um

#

13 different subclasses

fast shadow
pliant valley
#

first did you try adding a print at the front of your for loop

#

to see if its actually running/failing

fast shadow
#

like this

#

?

pliant valley
#

yeah

floral carbon
#

An infinite loop is not the outcome... There is no other modification of i other than the for loop.

Does it maybe hang in the Calculate method for the entry in scores[9]?

You need to do as SquidXTV suggests and find out where in the loop it is getting stuck.

fast shadow
pliant valley
#

hm

#

show us the implementation of (9)

fast shadow
#

i'm just going to look over the (9) subclass and fix it before i come back

#

thank you guys 🥺

fast shadow
#

okay so uh

#

this is (9)

summer crest
#

you might be stuck in else if

fast shadow
#

oh okay

#

it worked thanks

#

but how come there are spaces around 6