Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by TSR_Rajput · Nov 08, 2021 at 05:58 PM · whilewhile-loopwhile loop

Do-While Loop not working

I am using the While loop in the Start method. The code is as following:

     for (int i = 0; i < instPointsLength; i++)
     {
         int ranObj = Random.Range(0, ListLength);

         do
         {
             ranObj = Random.Range(0, ListLength);
             Debug.Log(ranObj);                
         }
         while (usedLocation.Contains(streetList[ranObj]) == true);

         instPointsList[i].transform.position = streetList[ranObj].transform.position;
         usedLocation.Add(streetList[ranObj]);
     }


Can anyone please help me out, why Unity is freezing, maybe because it becomes an Infinity Loop, but I can't find it out how? Because the list is empty for the first FOR loop iteration, the while loop will get a false and break, and similarly, for further iterations, it should break. Am I missing something, please let me know? Thanks a lot in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Perrorist · Nov 08, 2021 at 11:17 PM

If those last two statements are supposed to be in a While loop, shouldn't they be enclosed within {}?

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hellium · Nov 08, 2021 at 11:46 PM 0
Share

It's a do...while loop, not a while one.

avatar image Perrorist · Nov 08, 2021 at 11:49 PM 0
Share

I need my eyes testing.

avatar image TSR_Rajput Perrorist · Nov 09, 2021 at 06:46 AM 0
Share

It's okay, let me know if you find the issue. thanks for answering.

avatar image Perrorist · Nov 09, 2021 at 07:43 AM 0
Share

Did the Debug get executed?

avatar image TSR_Rajput Perrorist · Nov 09, 2021 at 07:50 AM 0
Share

Unity is freezing completely, so nothing works, no debugs

avatar image Perrorist · Nov 09, 2021 at 09:10 AM 0
Share

Have you considered adding a Debug before the For loop for InstPointsLength? Or are you saying Unity freezes before it even gets that far? Does commenting out the entire statement allow Unity to continue? (I'm just trying to get a proper understanding of the problem.)

avatar image TSR_Rajput Perrorist · Nov 09, 2021 at 09:17 AM 0
Share

Unity freezes after pressing the Play button, it completely freezes before executing anything. And commenting that makes everything work properly.

avatar image Perrorist · Nov 09, 2021 at 10:48 PM 0
Share

The question must be, is it the code itself or the inclusion of a section of code. I'm still new to Unity, so I don't have the knowledge or experience to understand why Unity is freezing, but I do have many years of program$$anonymous$$g under my belt. My approach would first be to replace the code with something innocuous, like a few statements that don't affect the program. If that works, I'd then reconsider the original code and attempt to achieve the same outcome with a different formulation, i.e. by replacing the Do...While with other constructs. It's worth a try.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

170 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

While loop freeze 0 Answers

[Solved]Cant Find loop that freezes Unity 2 Answers

Why is this Do/While loop hanging Unity? 1 Answer

NEED HELP PLEASE: When i kill a one of the three limited "mobSpawned" the "while (true)" don't work and don't spawn a new object. Anyone have a solution for this. Thanks. 1 Answer

While loop causing Unity to hang up? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges