在此 Go 程序中,for 循环的迭代从 A 开始到 Z 结束,以返回或显示大写字母 A 到 Z 之间的字母。
package main
import (
"fmt"
)
func main() {
fmt.Println("The List of Alphabets from A to Z are :")
for ch := 'A'; ch <= 'Z'; ch++ {
fmt.Printf("%c ", ch)
}
fmt.Println()
}

在这个 Golang 程序中,我们使用 for 循环迭代 ASCII 码(for ch := 65; ch <= 90; ch++)并显示从 A 到 Z 的字母。
package main
import (
"fmt"
)
func main() {
fmt.Println("The List of Alphabets from A to Z are :")
for ch := 65; ch <= 90; ch++ {
fmt.Printf("%c ", ch)
}
fmt.Println()
}
The List of Alphabets from A to Z are :
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
这个 Go 示例允许输入起始大写字母(for ch := stch; ch <= ‘Z’; ch++),并打印从该字母到 Z 的字母。
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter the Starting Character = ")
stch, _ := reader.ReadByte()
fmt.Printf("The List of Alphabets from %c to Z are :\n", stch)
for ch := stch; ch <= 'Z'; ch++ {
fmt.Printf("%c ", ch)
}
fmt.Println()
}
Enter the Starting Character = K
The List of Alphabets from K to Z are :
K L M N O P Q R S T U V W X Y Z