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