Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by AndreasX12 · Mar 24, 2013 at 10:21 AM · c#loopcarwheelfor

For loop C#?

Hello, I can't get my for loop working, this is the code:

 public int test = 1;    
     
 IEnumerator RotateWheelLeft() {
     for (test i = 0; i = 50; i++) {
             // stuff
         }
             
     }

The error is: CarScript.test' is a field' but a `type' was expected

Thanks, Andreas

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

2 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by Khada · Mar 24, 2013 at 10:27 AM

 test i = 0; //only makes sense if 'test' is a type that can be set to 0
 int i = 0; //an int is a type that can be set to 0 and used as a loop counter

All variable declarations use the following structure:

 //type   name   =   value
   int    num    =   0;
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 AndreasX12 · Mar 24, 2013 at 10:31 AM 0
Share

Okay, now I changed the code to this

     IEnumerator RotateWheelLeft() {
     for (int i = 0; i = 50; i++) {
             //Stuff
         }
             
     }

But I now get this error ins$$anonymous$$d: Cannot implicitly convert type int' to bool'

avatar image FLASHDENMARK · Mar 24, 2013 at 10:36 AM 0
Share

It should be:

for(int i = 0; i < 50; i++)

(I think)

avatar image AndreasX12 · Mar 24, 2013 at 10:45 AM 0
Share

Hmmm det bliver desværre heller ikke meget bedre af det :-)

avatar image AndreasX12 · Mar 24, 2013 at 10:50 AM 0
Share

Here's all the code

 using UnityEngine;
 using System.Collections;
 
 public class CarScript : $$anonymous$$onoBehaviour {
     
 
     // Use this for initialization
     void Start () {
 StartCoroutine("RotateWheelLeft");    
     }
     
     public int g;
 
     
     IEnumerator RotateWheelLeft() {
     for (int i = 0; i < 50; i++) {
             g += 1;
         }
             
     }
 
     
 }
 

Error: `CarScript.RotateWheelLeft()': not all code paths return a value

avatar image FLASHDENMARK · Mar 24, 2013 at 10:51 AM 1
Share

Uh, en dansker!

Får du fejlen "not all code paths return a value"? I så fald:

 void RotateWheelLeft() {
     for (int i = 0; i < 50; i++) {
          // stuff
     }
 }

Skal du skifte 'IEnumerator' ud med 'void'

Show more comments
avatar image
0

Answer by chrisspinu · Mar 21, 2020 at 04:38 PM

for (int i = 0; i == 50; i++) { // stuff } // You need to add two equals

Comment
Add comment · Show 1 · 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 Bunny83 · Mar 22, 2020 at 04:46 AM 1
Share

This makes no sense, First you bumped a question that was asked over 7 years ago and has already been answered. Second using == in the condition doesn't make any sense since your loop wouldn't run at all. You set i to 0 and you only run your loop while i is 50 which is not the case to begin with so the loop isn't executed at all.

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

14 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

Related Questions

C# for loop with 2 ints 2 Answers

How to make wheels turn more? 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Using for as while. 3 Answers


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