Breaking a foreach loop

Brad King brad.king at kitware.com
Wed Apr 19 16:52:48 CEST 2006


Pino Toscano wrote:
> Alle 16:20, martedì 18 aprile 2006, Brad King ha scritto:
> 
>>Pino Toscano wrote:
>>
>>>Hello,
>>>
>>>imagine I'm iterating using a foreach() like this:
>>>set(MY_OPTS "foo bar etc")
>>>foreach(OPT ${MY_OPTS})
>>>  # do something ...
>>>endforeach(OPT ${MY_OPTS})
>>>
>>>is there a way to break the iteration, just like a break in C?
>>>
>>>Whether it exist, does it break even nested foreach()?
>>
>>This is not possible, but you can simulate it yourself:
>>
>>SET(OPT_DONE 0)
>>foreach(opt ${MY_OPTS})
>>   if(NOT OPT_DONE)
>>     #...code...
>>     if(..need to break..)
>>       set(OPT_DONE 1)
>>     endif(..need to break..)
>>   endif(NOT OPT_DONE)
>>endforeach(opt)
> 
> That is not what I would like, as this would continue executing the loop. And 
> if the foreach loop is inside another foreach loop, having to execute all the 
> iterations is not my best plan...

If you have processing logic that complicated and expensive then CMake 
code may not be the proper place for it.  What are you trying to do?

-Brad


More information about the Kde-buildsystem mailing list