Skip to content

Latest commit

 

History

History
28 lines (24 loc) · 542 Bytes

File metadata and controls

28 lines (24 loc) · 542 Bytes

String

One thing that feels like it should implement the Iterable interface but does not is String.

~class Main {
~   void main() {
String letters = "abc";
for (char letter : letters) {
    IO.println(letter);
}
~   }
~}

To loop over all the characters in a String, you have to use a regular loop.

~class Main {
~   void main() {
String letters = "abc";
for (int i = 0; i < letters.length(); i++) {
    char letter = letters.charAt(i);
    IO.println(letter);
}
~   }
~}