How can I run for until a condition is met? Instead of using scala.util.control.Breaks.break, is it possible to test for a condition within for?
for(line <- source.getLines) {
if (line.equals("")) scala.util.control.Breaks.break
Console print "Message> "
dataWriter.write(line, InstanceHandle_t.HANDLE_NIL)
}
} catch {
case e: IOException =>{
Try takeWhile
for(line <- source.getLines.takeWhile(!_.isEmpty)) {
Console print "Message> "
dataWriter.write(line, InstanceHandle_t.HANDLE_NIL)
}
or
source.getLines.takeWhile(!_.isEmpty).foreach {
line =>
Console print "Message> "
dataWriter.write(line, InstanceHandle_t.HANDLE_NIL)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With