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. Going back to original IF statement if another one returns false

Going back to original IF statement if another one returns false

Scheduled Pinned Locked Moved C#
questionhelp
4 Posts 4 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.
  • B Offline
    B Offline
    Baeltazor
    wrote on last edited by
    #1

    Hi all I have a problem here and i'd appreciate any advice at all... I have like 20-something IF statements end else and else if (sample below)

    if( something.Text != otherthing.Text )
    {
    if( MessageBox.Show("Really?") == DialogResult.OK )
    {
    // do something
    }
    else { // now i want to go to the top and start from the first iff statement again. }
    }
    else Application.DoEvents();

    ...Except there's lots more if/else statements nested within one another. And it's very very time-consuming, confusing and after a while it just becomes too much to wrap my brain around. So I guess my question is... I vaigly remember somebody telling me to use Switch/Case things but I've tried reading about them on MSDN and I just can't seem to get my head around it can somebody please explain to me how the switch/case things would work.. In the most dumbest possible way? :P thanks for your time. thanks lots :D jase p.s. sorry if my message doesn't make much sense this time, i haven't slept in 48hours lol :laugh:

    L C P 3 Replies Last reply
    0
    • B Baeltazor

      Hi all I have a problem here and i'd appreciate any advice at all... I have like 20-something IF statements end else and else if (sample below)

      if( something.Text != otherthing.Text )
      {
      if( MessageBox.Show("Really?") == DialogResult.OK )
      {
      // do something
      }
      else { // now i want to go to the top and start from the first iff statement again. }
      }
      else Application.DoEvents();

      ...Except there's lots more if/else statements nested within one another. And it's very very time-consuming, confusing and after a while it just becomes too much to wrap my brain around. So I guess my question is... I vaigly remember somebody telling me to use Switch/Case things but I've tried reading about them on MSDN and I just can't seem to get my head around it can somebody please explain to me how the switch/case things would work.. In the most dumbest possible way? :P thanks for your time. thanks lots :D jase p.s. sorry if my message doesn't make much sense this time, i haven't slept in 48hours lol :laugh:

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

      Hi, I don't see how a switch might help you, retries means looping. occasionally I put stuff like that inside a big loop, which provides automatic retries, until either something succeeds, or there is sufficient reason to abandon (in both cases use break or return). Furthermore, it depends on what exactly you want to achieve, I sometimes use the if structures to set some bool flags, then when all decisions have been made, I execute what each bool flag stands for in straight code. BTW: don't try recursion on this! :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


      1 Reply Last reply
      0
      • B Baeltazor

        Hi all I have a problem here and i'd appreciate any advice at all... I have like 20-something IF statements end else and else if (sample below)

        if( something.Text != otherthing.Text )
        {
        if( MessageBox.Show("Really?") == DialogResult.OK )
        {
        // do something
        }
        else { // now i want to go to the top and start from the first iff statement again. }
        }
        else Application.DoEvents();

        ...Except there's lots more if/else statements nested within one another. And it's very very time-consuming, confusing and after a while it just becomes too much to wrap my brain around. So I guess my question is... I vaigly remember somebody telling me to use Switch/Case things but I've tried reading about them on MSDN and I just can't seem to get my head around it can somebody please explain to me how the switch/case things would work.. In the most dumbest possible way? :P thanks for your time. thanks lots :D jase p.s. sorry if my message doesn't make much sense this time, i haven't slept in 48hours lol :laugh:

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        I assume this whole method is being called over and over. Therefore, you don't need an else on the inside, just wait for it to run again. At worst, put your Application.DoEvents inside the other else.

        Christian Graus Driven to the arms of OSX by Vista. "! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums. I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp

        1 Reply Last reply
        0
        • B Baeltazor

          Hi all I have a problem here and i'd appreciate any advice at all... I have like 20-something IF statements end else and else if (sample below)

          if( something.Text != otherthing.Text )
          {
          if( MessageBox.Show("Really?") == DialogResult.OK )
          {
          // do something
          }
          else { // now i want to go to the top and start from the first iff statement again. }
          }
          else Application.DoEvents();

          ...Except there's lots more if/else statements nested within one another. And it's very very time-consuming, confusing and after a while it just becomes too much to wrap my brain around. So I guess my question is... I vaigly remember somebody telling me to use Switch/Case things but I've tried reading about them on MSDN and I just can't seem to get my head around it can somebody please explain to me how the switch/case things would work.. In the most dumbest possible way? :P thanks for your time. thanks lots :D jase p.s. sorry if my message doesn't make much sense this time, i haven't slept in 48hours lol :laugh:

          P Offline
          P Offline
          PunkIsNotDead
          wrote on last edited by
          #4

          You can't return to an IF statement...


          Well and about the switch, it's easy to use... you only have to watch the switch value, cause with it you're going to work in the 'case' statements... ex:


          foreach (DataRow dr in ((DataTable)this.Dgv_Datos.DataSource).Rows)
          {
          switch (dr.RowState)
          {
          case DataRowState.Modified:
          Regionalidades.Id_Regionalidad = Convert.ToInt32(dr["Id_Regionalidad"]);
          Regionalidades.NombreRegionalidad = dr["NombreRegionalidad"].ToString();
          Regionalidades.modificar(); }
          break;
          case DataRowState.Added:
          Regionalidades.NombreRegionalidad = dr["NombreRegionalidad"].ToString();
          Regionalidades.insertar(); }
          break;
          case DataRowState.Deleted:
          Regionalidades.Id_Regionalidad = Convert.ToInt32(dr["Id_Regionalidad", DataRowVersion.Original].ToString());
          Regionalidades.eliminar();
          break;
          }
          }


          If you see over there, i've used the DataRow 'dr' to verify the RowState (Added, Modified or Deleted) of a DataGridViewRow... well the Namespace Regionalidades is a reference for the class, so it doesn't matter in the code... well i hope it helps... :suss:

          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