3xodus
Well-known member
Hi again all,
Sorry for the basic question, but Im having trouble finding this information. In MSDN and on the various C# Tutorials and websites Ive read, they give examples but dont give information on the flow of the program in an if statement in C#.
The particular code Im having trouble with is:
I want this section of code to loop until either a != b, or a == -1, but it seems its not looping and I believe this is because of my if statements. To be honest, Im not sure that much of the above code is correct (it builds, but I think its not the result I was aiming for)
Im used to VB, where I can do End If to end the if statement, and the program will continue to the line after "End If" - it seems to me that in C# that isnt the case, but since I havent been able to find much good information Im not sure.
Please could anyone explain how C# if statements work? As I understand it at the moment, the "}" at the end of the statement ends not only the if statement, but the whole function which the code is in (unless a certain result is returned), but I cant figure out how, if that is the case, it works.
Any help or links are greatly appreciated - I suppose since this is a basic subject, the info is out there - Ive just managed to miss it
Sorry for the basic question, but Im having trouble finding this information. In MSDN and on the various C# Tutorials and websites Ive read, they give examples but dont give information on the flow of the program in an if statement in C#.
The particular code Im having trouble with is:
C#:
do
{
// get data to perform conditional statement on
if (a != b)
{
if ( c == d )
// do something
if ( c != d )
{
// do something different
}
}
}
while ((a == b) && (a != -1));
MessageBox.Show("Done");
}
I want this section of code to loop until either a != b, or a == -1, but it seems its not looping and I believe this is because of my if statements. To be honest, Im not sure that much of the above code is correct (it builds, but I think its not the result I was aiming for)
Im used to VB, where I can do End If to end the if statement, and the program will continue to the line after "End If" - it seems to me that in C# that isnt the case, but since I havent been able to find much good information Im not sure.
Please could anyone explain how C# if statements work? As I understand it at the moment, the "}" at the end of the statement ends not only the if statement, but the whole function which the code is in (unless a certain result is returned), but I cant figure out how, if that is the case, it works.
Any help or links are greatly appreciated - I suppose since this is a basic subject, the info is out there - Ive just managed to miss it