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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:26:30+00:00 2026-05-29T21:26:30+00:00

I have a situation where I have to do some thing like this for

  • 0

I have a situation where I have to do some thing like this

for (int i = 0; i < list.size; i++) //Master for loop
{ 
    //I need a control statement here to control list1 i.e. only if statement

    if (time == list1.get(someInteger))
    {
        //do something
    }
    else
    {
        //do something else
    }
}

But every “if” should be followed by an “else”, and I don’t seem to understand how to go about it. Ive tried do and while but to no avail. For me it is important to execute both if and else, yet have a control statement for only “if”.

Is that possible?

  • 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-29T21:26:32+00:00Added an answer on May 29, 2026 at 9:26 pm

    With your current constraints and description and rational assumptions No.

    For me it is important to execute both if and else, yet have a control
    statement for only “if”.

    This violates the specification of what a if...else... is. You cannot execute both if and else and keep the if...else... structure. Logically you could drop the else and just have the code in the else inside the loop as other answers have pointed out. However, if you actually do need to keep if and else you need to clarify why so we have a context to answer your question.

    If there is some tricky stuff unstated here you might also have a look at switch and use a Goto Case setup. Might be worth saying this probably wouldn’t be recommended by many seasoned programmers. Switch statement fallthrough in C#?

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

Sidebar

Related Questions

I have a situation like this: start(); <Some code> end(); I want start() function
I have a situation where I need to do something like select 2, id
I have a situation where I need to notify some users when something in
Here's the situation: We have some generic graphics code that we use for one
Suppose I have a class like this class A { private int _x; //must
The situation is like this: I have a WCF host with a duplex nettcpbinding
Simple situation. I have a list of lists, almost table like, and I am
In C++ methods can have optional arguments, like this: void myFunction (int arg1, int
In a situation where you have something like a Lite, Normal, Ultimate tiers and
Situation: I have some persons with certain skills and they can/might belong to more

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.