while loop

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)”


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

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:

Linux shell scripts: How to increment a counter in a shell script

Unix/Linux shell script FAQ: Can you share a simple Linux shell script that shows how to count, i.e., a shell script that increments a counter in a for loop or while loop?

Sure, I just needed to increment a while loop counter myself, so I thought I'd share my example shell script code here.

Java while loop example

Java while loop FAQ: Can you show me an example of a Java while loop?

Sure, here's a Java while loop example:

package com.devdaily.javasamples;

public class WhileTest
  public static void main(String[] args)
    int i = 0;
    while (i < 5)
      System.out.println("i = " + i);

This example prints out the value of the variable i until i gets to 5, at which point the loop stops.