// Forcodes.swift Copyright (c) Kari Laitinen // http://www.naturalprogramming.com // 2014-09-26 File created. // 2016-08-11 Last modification. // This program demonstrates a for-in loop and an if construct // inside the loop. import Foundation var number_of_codes_on_this_line = 0 print( "\n The visible characters with codes from 20" + "\n to 7F (hexadecimal) are the following:\n\n ", terminator: "" ) for numerical_code in 0x20 ... 0x7F { // The numerical code will be printed both as a character and // as a hexadecimal value. print( String( format: "%c %X ", numerical_code, numerical_code ), terminator: "" ) number_of_codes_on_this_line += 1 if number_of_codes_on_this_line == 8 { print( "\n ", terminator: "" ) number_of_codes_on_this_line = 0 } } print( "\n" )