Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

For loop skipping in the middle

Discussion in 'Scripting' started by knobblez, Feb 25, 2022.

  1. knobblez

    knobblez

    Joined:
    Nov 26, 2017
    Posts:
    223
    I am trying to debug a problem but when I run this code it skips if there is two letters in a row:
    For example, I ran it with the word 'crooked' and it logs 'croked'. I have tried multiple words. Works perfectly with words like 'abdomen' or 'monkeys'.


    Code (CSharp):
    1.                         for (int i = 0; i < 7; i++)
    2.                         {
    3.                             letter = theWord[i];
    4.                             Debug.Log(letter.ToString());
    5. ...
     
  2. Trafulgoth

    Trafulgoth

    Joined:
    Jun 5, 2013
    Posts:
    45
    What's probably happening is that you have your editor console set to collapse identical messages. So, the double letters are being printed, but instead of getting two console messages, you get one message with a (2) next to it.
     
    Bunny83, michael22 and knobblez like this.
  3. knobblez

    knobblez

    Joined:
    Nov 26, 2017
    Posts:
    223
    That was it. Thank you very much
     
  4. michael22

    michael22

    Joined:
    Mar 29, 2015
    Posts:
    2
    nothing is wrong with the code you posted, so the problem is somewhere else. you didnt run it with 'crooked' you ran it with the variable "theWord", so i dont know how what you did before. for the future you should post a more verbose example. also this code wont support any word that has more than seven characters...