/* * controls.go *------------------------------------------------------- * if, for, and switch is all you get * Jim Fawcett, CSE775 - Distributed Objects, Spring 2016 *------------------------------------------------------- */ package main import ( "fmt" "strings" "fawcett/utils" ) func display1(s string) { fmt.Print("\n ") for i := 0; i < len(s); i++ { // classic for loop fmt.Printf("%c", s[i]) } } func display2(s string) { fmt.Print("\n ") for _, ch := range s { // range returns index and value at index then increments fmt.Printf("%c", ch) // we are ignoring index by using _ receiver } } func display3(s string) { fmt.Print("\n ") i := 0 for { // like while(true) { ... } fmt.Printf("%c", s[i]) i++ if i == len(s) { // if statements must have scope braces break } } } func countWords(s string) (theWords, forWords, toWords int) { words := strings.Split(s, " ") for i:=0; i