September 04, 2010, 02:02:29 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  Home Help Media Affiliates Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: For looping  (Read 843 times)
0 Members and 1 Guest are viewing this topic.
jurka
Moderator
Member
*
*

Reputation: 5
Offline Offline
Posts: 188
Referrals: 0

Awards
« on: March 18, 2009, 03:23:45 AM »

As there are lot of different ways to use the for loop compared to Java. Ill try to post my own examples and the book examples.

Simple Java's for-each could be in Scala
Code
GeSHi (java):
  1. scala> val list = 12 :: 32 :: 4 :: 4 :: Nil
  2. list: List[Int] = List(12, 32, 4, 4)
  3.  
  4. scala> for (i <- list) println(i)
  5.  
Created by GeSHI 1.0.7.20
Result :
12
32
4
4

You can filter the results
Code
GeSHi (java):
  1. scala> for (i <- list; if i < 5) println(i)
  2.  
Created by GeSHI 1.0.7.20
Result:
4
4
Logged
Javaforums.net :: a community about Java software development.
« on: March 18, 2009, 03:23:45 AM »

Your Ad Here
 Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Valid XHTML 1.0! Valid CSS!
Page created in 0.163 seconds with 35 queries.

Google visited last this page August 25, 2010, 06:48:22 AM