loop control
-
Hi, The code looks as follows:
for() //main for loop { for() //for loop1 { if(condition) { //code } } for() //for loop2 { } for() //for loop3 { } }
If the condition is false I want to iterate the main loop without running following for loops. How to do this? Best Regards, Suman -
Hi, The code looks as follows:
for() //main for loop { for() //for loop1 { if(condition) { //code } } for() //for loop2 { } for() //for loop3 { } }
If the condition is false I want to iterate the main loop without running following for loops. How to do this? Best Regards, SumanJust put the
continue
keyword if the condition is true:if (condition)
continue;This will go to the next iteration of the current loop.
Cédric Moonen Software developer
Charting control [v1.3 - Updated] -
Hi, The code looks as follows:
for() //main for loop { for() //for loop1 { if(condition) { //code } } for() //for loop2 { } for() //for loop3 { } }
If the condition is false I want to iterate the main loop without running following for loops. How to do this? Best Regards, SumanYou can use also goto in the following manner.
:loop1 for() //main for loop
{
for() //for loop1
{
if(condition)
{
//code
goto Loop1;} }
for() //for loop2
{
}
for() //for loop3
{
}
}[ Screen Capture ][ Tool Tip ][ Muliple Desktops ][Greeting Card ]
-
Just put the
continue
keyword if the condition is true:if (condition)
continue;This will go to the next iteration of the current loop.
Cédric Moonen Software developer
Charting control [v1.3 - Updated]Hi Thanks for the help, continue is iterating the current loop but not the main (outer) for loop. break will just break the current for loop but other loops following it will be executed. The "goto" is working, if its standard way I want use it. Thanks, Suman
-
You can use also goto in the following manner.
:loop1 for() //main for loop
{
for() //for loop1
{
if(condition)
{
//code
goto Loop1;} }
for() //for loop2
{
}
for() //for loop3
{
}
}[ Screen Capture ][ Tool Tip ][ Muliple Desktops ][Greeting Card ]
Hi, Thanks for the help!! Presently, I am using the "goto". "goto" seems smarter than checking the same condition in all for loops and "break"ing from them. With Thanks, Suman BTW,
GauranG Shah wrote:
:loop1 for() //main for loop
Did you mean "loop1: for()", the colon after label?
-
Hi, Thanks for the help!! Presently, I am using the "goto". "goto" seems smarter than checking the same condition in all for loops and "break"ing from them. With Thanks, Suman BTW,
GauranG Shah wrote:
:loop1 for() //main for loop
Did you mean "loop1: for()", the colon after label?
rp_suman wrote:
Presently, I am using the "goto". "goto" seems smarter than checking the same condition in all for loops and "break"ing from them.
Not really. The goto statement should rarely be used. It could be used when your application is really time critical. In any other case you should try to use condition.
for() //main for loop { for() //for loop1 { if(condition) { //code } } if(!condition) { for() //for loop2 { } for() //for loop3 { } } // end if(!condition) }
codito ergo sum
-
rp_suman wrote:
Presently, I am using the "goto". "goto" seems smarter than checking the same condition in all for loops and "break"ing from them.
Not really. The goto statement should rarely be used. It could be used when your application is really time critical. In any other case you should try to use condition.
for() //main for loop { for() //for loop1 { if(condition) { //code } } if(!condition) { for() //for loop2 { } for() //for loop3 { } } // end if(!condition) }
codito ergo sum