continue in a for-loop

1,345 views
Skip to first unread message

chris...@gmail.com

unread,
Jun 24, 2013, 12:00:06 PM6/24/13
to xtend...@googlegroups.com
Hi, 

how can i continue in a for loop? This doesn't compile, continue seems to be no keyword:

for ( it:list(networkInterfaces)){
if (!isPointToPoint())
  continue; //compile error
if (!isUp())
continue;
//now do something useful with it
}

thanks 
Chris

Jan Köhnlein

unread,
Jun 24, 2013, 1:30:33 PM6/24/13
to xtend...@googlegroups.com
Statements like 'continue', 'break' and 'goto' are not part of Xtend. Neither are labels.
These stand a bit against the functional nature of Xtend.

Your example can be easily transformed.

for (it: list(networkInterfaces)){
if (isPointToPoint() && isUp()) {
> --
> You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
Dr. Jan Köhnlein
Senior Software Architekt

Mobile: +49 (0) 151 / 17396687
Telefon: +49 (0) 431 / 99026870
Fax: +49 (0) 431 / 99026872

http://www.itemis.de
jan.ko...@itemis.de
https://www.xing.com/profile/Jan_Koehnlein

itemis AG
Niederlassung Kiel
Am Germaniahafen 1
24143 Kiel
http://www.itemis.de/

Rechtlicher Hinweis:

Amtsgericht Dortmund, HRB 20621

Vorstand: Jens Wagener (Vors.), Wolfgang Neuhaus, Dr. Georg Pietrek, Jens Trompeter, Sebastian Neus

Aufsichtsrat: Dr. Burkhard Igel (Vors.), Stephan Grollmann, Michael Neuhaus

Zsombor

unread,
Jun 24, 2013, 5:29:06 PM6/24/13
to xtend...@googlegroups.com
More functional would be:
list(networkInterfaces).filter[ isPointToPoint && isUp ].map[ .... ]

BR,
 Zsombor

chris...@gmail.com

unread,
Jun 24, 2013, 7:16:08 PM6/24/13
to xtend...@googlegroups.com, gzso...@gmail.com
yea, i figured out the function-style too, now my code looks like this:

    def printAll(Enumeration<NetworkInterface> networkInterfaces, Predicate<NetworkInterface> filter){
        forEnumeration(networkInterfaces).filter(filter).forEach[println(it)]
    }

Now one can use networkInterfaces.printAll[up && pointToPoint] to print all NetworkInterface's using a filter. Xtend did a good job to create a clear and expressive api, once one understand closures/lambdas.

I was surprised that some methods are silently imported. In this case it was filter that was imported from org.eclipse.xtext.xbase.lib.IteratorExtensions, i replaced it by guava's Iterables.filter(Iterable) so i could use it with a guava Predicate. Another surprise was that one have to write .forEach[println(it)] instead of .forEach[println] the variable it will not be applied to println for some reason.

Sven Efftinge

unread,
Jul 7, 2013, 2:53:11 PM7/7/13
to xtend...@googlegroups.com
On Jun 25, 2013, at 1:16 AM, chris...@gmail.com wrote:

I was surprised that some methods are silently imported. In this case it was filter that was imported from org.eclipse.xtext.xbase.lib.IteratorExtensions, i replaced it by guava's Iterables.filter(Iterable) so i could use it with a guava Predicate. Another surprise was that one have to write .forEach[println(it)] instead of .forEach[println] the variable it will not be applied to println for some reason.

This is because println is not imported as an extension method, so you cannot write it.println() either.
Xtend doesn't support implicit parameters as Scala does.

Sven
Reply all
Reply to author
Forward
0 new messages