培基
類
纂行號型
纂若夫此類,蓋句首行號也。解釋器依行號而行,順勢而下,然世人詬以行號,以為麵條。
10 INPUT "爾何名: ", U$
20 PRINT "無恙 "; U$
30 INPUT "爾欲星幾何: ", N
40 S$ = ""
50 FOR I = 1 TO N
60 S$ = S$ + "*"
70 NEXT I
80 PRINT S$
90 INPUT "其餘? ", A$
100 IF LEN(A$) = 0 THEN GOTO 90
110 A$ = LEFT$(A$, 1)
120 IF A$ = "Y" OR A$ = "y" THEN GOTO 30
130 PRINT "請歸 "; U$
140 END
結構型
纂若夫此類,行號更易,標籤代之。
INPUT "爾何名: ", UserName$
PRINT "無恙 "; UserName$
DO
INPUT "爾欲星幾何 ", NumStars
Stars$ = STRING$(NumStars, "*")
PRINT Stars$
DO
INPUT "其餘? ", Answer$
LOOP UNTIL Answer$ <> ""
Answer$ = LEFT$(Answer$, 1)
LOOP WHILE UCASE$(Answer$) = "Y"
PRINT "請歸 "; UserName$
對象型
纂若夫此類,編譯器代之以解釋器,自立可行。
Public Class StarsProgram
Public Shared Sub Main()
Dim UserName, Answer, stars As String, NumStars As Integer
Console.Write("爾何名: ")
簿名= Console.ReadLine()
Console.WriteLine("無恙 {0}", 簿名)
Do
Console.Write("爾欲星幾何 ")
星之數 = CInt(Console.ReadLine())
星 = New String("*", NumStars)
Console.WriteLine(星)
Do
Console.Write("其餘? ")
答 = Console.ReadLine()
Loop Until Answer <> ""
答 = 答.Substring(0, 1)
Loop While 答.ToUpper() = "Y"
Console.WriteLine("請歸 {0}", 簿名)
End Sub
End Class