Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Nested if statements

Nested if statements

Scheduled Pinned Locked Moved C#
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wheels012
    wrote on last edited by
    #1

    Good afternoon. I was wondering if there is a more efficient way to write this code:

    //Resets the browser to the previous page when an item is deleted.
    if (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1)
    {
    WebBrowser1.GoBack();
    }
    else if (cboWS.SelectedIndex == -1 && inttmpWS != -1)
    {
    WebBrowser1.GoBack();
    }
    else if (cboFolder.SelectedIndex == -1 && inttmpF != -1)
    {
    WebBrowser1.GoBack();
    }

    I want to call the WebBrowser1.GoBack(); once if possible. Thank you, WHEELS

    L S 2 Replies Last reply
    0
    • W Wheels012

      Good afternoon. I was wondering if there is a more efficient way to write this code:

      //Resets the browser to the previous page when an item is deleted.
      if (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1)
      {
      WebBrowser1.GoBack();
      }
      else if (cboWS.SelectedIndex == -1 && inttmpWS != -1)
      {
      WebBrowser1.GoBack();
      }
      else if (cboFolder.SelectedIndex == -1 && inttmpF != -1)
      {
      WebBrowser1.GoBack();
      }

      I want to call the WebBrowser1.GoBack(); once if possible. Thank you, WHEELS

      S Offline
      S Offline
      Saksida Bojan
      wrote on last edited by
      #2

      Wheels012 wrote:

      I want to call the WebBrowser1.GoBack(); once if possible.

      Do nested If

      if (cboSP_Site.SelectedIndex == -1)
      {
      if (inttmSP != -1 || inttmpWS != -1 || inttmpF != -1)
      WebBrowser1.GoBack();
      }

      I hope i did it correctly

      L 1 Reply Last reply
      0
      • W Wheels012

        Good afternoon. I was wondering if there is a more efficient way to write this code:

        //Resets the browser to the previous page when an item is deleted.
        if (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1)
        {
        WebBrowser1.GoBack();
        }
        else if (cboWS.SelectedIndex == -1 && inttmpWS != -1)
        {
        WebBrowser1.GoBack();
        }
        else if (cboFolder.SelectedIndex == -1 && inttmpF != -1)
        {
        WebBrowser1.GoBack();
        }

        I want to call the WebBrowser1.GoBack(); once if possible. Thank you, WHEELS

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        there are many ways to get what you want, here is one:

        if ((cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) ||
        (cboWS.SelectedIndex == -1 && inttmpWS != -1) ||
        (cboFolder.SelectedIndex == -1 && inttmpF != -1)) {
        WebBrowser1.GoBack();
        }

        and another one:

        bool goBack=false;
        if (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) goBack=true;
        else if (cboWS.SelectedIndex == -1 && inttmpWS != -1) goBack=true;
        else if (cboFolder.SelectedIndex == -1 && inttmpF != -1)) goBack=true;
        if (goBack) WebBrowser1.GoBack();

        BTW: here the "else" keywords are optional :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        modified on Monday, November 30, 2009 4:23 PM

        W 1 Reply Last reply
        0
        • S Saksida Bojan

          Wheels012 wrote:

          I want to call the WebBrowser1.GoBack(); once if possible.

          Do nested If

          if (cboSP_Site.SelectedIndex == -1)
          {
          if (inttmSP != -1 || inttmpWS != -1 || inttmpF != -1)
          WebBrowser1.GoBack();
          }

          I hope i did it correctly

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Saksida Bojan wrote:

          I hope i did it correctly

          Not really. Every letter counts here. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


          1 Reply Last reply
          0
          • L Luc Pattyn

            there are many ways to get what you want, here is one:

            if ((cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) ||
            (cboWS.SelectedIndex == -1 && inttmpWS != -1) ||
            (cboFolder.SelectedIndex == -1 && inttmpF != -1)) {
            WebBrowser1.GoBack();
            }

            and another one:

            bool goBack=false;
            if (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) goBack=true;
            else if (cboWS.SelectedIndex == -1 && inttmpWS != -1) goBack=true;
            else if (cboFolder.SelectedIndex == -1 && inttmpF != -1)) goBack=true;
            if (goBack) WebBrowser1.GoBack();

            BTW: here the "else" keywords are optional :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


            modified on Monday, November 30, 2009 4:23 PM

            W Offline
            W Offline
            Wheels012
            wrote on last edited by
            #5

            Thank you Luc.

            if ((cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) ||
            (cboWS.SelectedIndex == -1 && inttmpWS != -1) ||
            (cboFolder.SelectedIndex == -1 && inttmpF != -1)) {
            WebBrowser1.GoBack();
            }

            Is what I am looking for. A little slow today. WHEELS

            R 1 Reply Last reply
            0
            • W Wheels012

              Thank you Luc.

              if ((cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) ||
              (cboWS.SelectedIndex == -1 && inttmpWS != -1) ||
              (cboFolder.SelectedIndex == -1 && inttmpF != -1)) {
              WebBrowser1.GoBack();
              }

              Is what I am looking for. A little slow today. WHEELS

              R Offline
              R Offline
              Ravi Bhavnani
              wrote on last edited by
              #6

              5 years from now, you'll probably be scratching your head over what this code does.  At the risk of being chastised for writing more code, I suggest you amend the code to:

              bool itemDeleted = (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) ||
              (cboWS.SelectedIndex == -1 && inttmpWS != -1) ||
              (cboFolder.SelectedIndex == -1 && inttmpF != -1);
              if (itemDeleted) {
              WebBrowser1.GoBack();
              }

              /ravi

              My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

              J W 2 Replies Last reply
              0
              • R Ravi Bhavnani

                5 years from now, you'll probably be scratching your head over what this code does.  At the risk of being chastised for writing more code, I suggest you amend the code to:

                bool itemDeleted = (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) ||
                (cboWS.SelectedIndex == -1 && inttmpWS != -1) ||
                (cboFolder.SelectedIndex == -1 && inttmpF != -1);
                if (itemDeleted) {
                WebBrowser1.GoBack();
                }

                /ravi

                My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                J Offline
                J Offline
                JollyMansArt
                wrote on last edited by
                #7

                I agree.

                L 1 Reply Last reply
                0
                • J JollyMansArt

                  I agree.

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  that's why I offered some alternatives, you pick whichever you like most. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                  1 Reply Last reply
                  0
                  • R Ravi Bhavnani

                    5 years from now, you'll probably be scratching your head over what this code does.  At the risk of being chastised for writing more code, I suggest you amend the code to:

                    bool itemDeleted = (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) ||
                    (cboWS.SelectedIndex == -1 && inttmpWS != -1) ||
                    (cboFolder.SelectedIndex == -1 && inttmpF != -1);
                    if (itemDeleted) {
                    WebBrowser1.GoBack();
                    }

                    /ravi

                    My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                    W Offline
                    W Offline
                    Wheels012
                    wrote on last edited by
                    #9

                    Thank you ravi. Good code. WHEELS

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups