Is there a way to tell the program to continue reading the next line of code whithing a nested IF statement?
The reason I want to do this is because the two "else" statements in the following sample (the main and the nested else) will contain the same exact code and I don't want to repeate it twice. I know I can do this by creating a function and calling it from each else statement but I was just wondering if what I'm asking is even possible without using a function.
if(1 < 2)
{
// yes 1 is less than 2
if(5 > 10)
{
// do something
}
else
{
// no, 5 in not greater than 10
// here is where I want to tell the program to continue reading the next else statement
// since it contains the code I want, otherwise I would need to add the same
// code here again
}
}
else
{
// doing something else
}
Something like...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
if(1 < 2)
{
// yes 1 is less than 2
if(5 > 10)
{
// do something
}
else
{
continue; // go to the next line
}
}
else
{
// doing something else
}
I don't understand your question. Unless you put a loop in, i.e. do {...} while(condition); or for(int idx=0; idx<total; ++idx){...} etc, then the next line of your program will be run...
Line 5 will always be true and is likely to just be optimized out. What are you trying to test here?
Erm, I don't think 5 is greater than 10 lol.
I think I might know what he is asking. Perhaps what he means is how can he after going through the nested if-branch execute what's in the else statement in the first if-branch.
If that is indeed what is being asked, no. That doesn't work. It already tested for that if-branch and will skip any other scenarios part of it.
I think I might know what he is asking. Perhaps what he means is how can he after going through the nested if-branch execute what's in the else statement in the first if-branch.
If that is indeed what is being asked, no. That doesn't work. It already tested for that if-branch and will skip any other scenarios part of it.
This answers my question, thanks a lot and sorry about the confusion.