Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8028403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:07:43+00:00 2026-06-05T00:07:43+00:00

I didn’t know what else to use in this case but an if statement.

  • 0

I didn’t know what else to use in this case but an if statement.

What I am trying to do is I am getting a value string direction; from a Windows form and checking if it has the value I am looking for. Then checking if the turtleDir which is a string value indicating the direction turtleDir has.

The problem comes here at else if statements, when the turtleDir is lookingleft it does all of the else if statements. What I want it to do is after it has done that else if statement it needs to stop and wait for the next command. not go through all the statements.

Can someone please advise me on how to fix it and what I am doing wrong?

Here is the code:

else if ( Program.form.direction == "right" ) 
{
   if ( turtleDir == "left" )
   {
      angle = -1.6f;
      turtleDir = "lookingLeft";
      Program.form.direction = "";
   }
   else if ( turtleDir == "lookingLeft" )
   {
      angle = 3.15f;
      turtleDir = "lookingDown";
   }
   else if ( turtleDir == "lookingDown" )
   {
      angle = 1.6f;
      turtleDir = "lookingRight";
   }
   else if ( turtleDir == "lookingRight" )
   {
      angle = 0.0f;
      turtleDir = "lookingUp";   
   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:07:44+00:00Added an answer on June 5, 2026 at 12:07 am

    You can use a switch statement on strings, too:

    switch (turtleDir) {
        case "left":
            angle = -1.6f;
            turtleDir = "lookingLeft";
            Program.form.direction = "";
            break;
        case "lookingLeft":
            angle = 3.15f;
            turtleDir = "lookingDown";
            break;
        // other cases
    }
    

    This way, the switch block is always exited after your instructions are done. You can also specify what to do when the string matches none of these values by adding a case default: at the end. Remember each of these cases needs to be terminated by a break statement (or return/throw but i don’t think you need those in this case).

    If still every case is executed, your problem lies somewhere else. If a method contains this code and is called starting with e.g. turtleDir == "left", each successive call of the method will let turtleDir cycle until every case has been executed and turtleDir ends up with the final value "lookingUp". So look at your control flow and maybe keep track whether you already performed this check. Maybe keep track of the elapsed time and change turtleDir only if it has been in a particular state for a while (i don’t know your requirements).

    EDIT: You should set Program.form.direction = "" in every case statement. That’s why your code gets executed over and over again. Also, if no direction is entered, clear it, too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Didn't know how else to put this. Say I have a JavaScript method that
Didn't even know how to exactly phrase this question, but here is the the
I didn't really know how to formulate the title. But this is my problem.
Didn't find any from their website. I mostly just trying to see which one
I didn't understand this. This is used for filtering case insensitive: jQuery.expr[':'].Contains = function(a,i,m){
i didn't tested this code on iPhone but i'm sure (tested) it doesn't works
I didn't design this table, and I would redesign it if I could, but
I didn't use subviews but painted my things with -drawRect: inside an UIView subclass.
I didn't know how to express this problem that well in word form so
I didn't know how to Google this, it always came up with answers I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.