while

A Scala DSL example

I was just going through some old notes and found this Scala DSL example from 2010:

How to process every line in a file with a Unix/Linux shell script

Unix/Linux shell script FAQ: How do I write a Unix or Linux shell script where I "do something" for every line in a text file?

Solution: An easy way to process every line in a text file is to use a Unix/Linux while loop in combination with the Linux cat command, like this:

How to create your own control structures in Scala

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 3.18, “How to create your own control structures in Scala.”

Problem

You want to define your own control structures to improve the Scala language, simplify your own code, or create a DSL for others to use.

Scala: How to use break and continue in for and while loops

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 3.5, “ Scala: How to use break and continue in for loops (and while loops)”

Problem

You have a situation where you need to use a break or continue construct, but Scala doesn’t have break or continue keywords.

Scala control structure examples (if/then, match/case, for, while, try/catch)

This post contains a collection of Scala control structures examples. I initially created most of these in the process of writing the Scala Cookbook. Unlike the Cookbook, I don’t describe them much here, I just show the examples, mostly as a reference for myself (and anyone else that can benefit from them).

if/then control structures:

Here are some examples of the Scala if/then control structure:

The AppleScript for loop (and while loop) examples

AppleScript for loop FAQ: How do I use an AppleScript for loop? (Also, how do you use an AppleScript while loop?)

This is actually a bit of a trick question, as there is no AppleScript for loop or while loop syntax. Instead you use the AppleScript repeat command, as shown in the following examples.

AppleScript for loop examples

Where you might expect an AppleScript for loop to iterate over a list, you use the AppleScript repeat with syntax:

An AppleScript list iterate/loop example

AppleScript list FAQ: How do I iterate/loop over an AppleScript list?

As I continue to work on my Mac speech recognition software projects, I've often found the need to loop over an AppleScript list. One way to loop over an AppleScript list is to use the AppleScript repeat with syntax: