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 7494275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:25:38+00:00 2026-05-29T17:25:38+00:00

I have a vital infinite for loop that allows a sensor to keep updating

  • 0

I have a vital infinite for loop that allows a sensor to keep updating its values. However I would like to break that for loop when another sensor brings in new values. How can I switch from one infinite for loop to another?

Current code:

for(;;){

    SON_Start();
    // Wait 65ms for max range time
    delay10ms(7);
    // Read Range
    i = SON_Read(SON_ADDRESSES[sonarReading]);
    // pause
    delayMs(100);
        if(i<15)
        drive(200, RadCW);

    }

What I would like to add:

If Sensor2 returns a reading (e.g. Sensor2 > 20), then I want to break the loop and goto another infinite for loop to begin a new function.

  • 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-05-29T17:25:39+00:00Added an answer on May 29, 2026 at 5:25 pm

    If you are looking for “switching between 2 infinite loops” it could be “wrapped” by third loop and this “switching” could be done by simple break.

    But since you want your program to stop some day, this loop could be placed within the function and you could use return; for ending it:

    void myMagicLoop()
    {
        for(;;)
        {
            for(;;)
            {
                if ( I should stop )
                    return;
    
                if ( I should switch to second loop )
                    break;
            }
            for(;;)
            {
                if ( I should stop )
                    return;
    
                if ( I should switch back to first loop)
                    break;
            }
        }
    }
    

    And somewhere you just call:

    myMagicLoop();
    

    Hope this helps.

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

Sidebar

Related Questions

I have a couple of non-English texts. I would like to perform stylistic comparisons
I have a div that has scrollable content, but it is vital that this
I have begun creating a wpf mvvm app. It seems a vital ingredient to
I have a loop for(aI = antiviral_data.begin(); aI != antiviral_data.end();) { for(vI = viral_data.begin();
I have an anoying problem that is giving me a hard time these days...
I need to have a UserProfile class that it's just that, a user profile.
I have a Direct2D window which paints fine when in focus; however, when focus
I have a page with an iframe. Inside the iframe is code (that I
I have a rails app which requires users to verify that they own a
I have a particular piece of software that i wish to load on windows

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.