FizzBuzz/Basic

From Rosetta Code
< FizzBuzz
Revision as of 14:50, 31 August 2022 by PureFox (talk | contribs) (Fixed BASIC sub-headings.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
FizzBuzz/Basic is part of FizzBuzz. You may find other members of FizzBuzz at Category:FizzBuzz.

Applesoft BASIC[edit]

10  DEF  FN M(N) = ((A / N) -  INT (A / N)) * N
20  FOR A = 1 TO 100
30  LET O$ = ""
40  IF  FN M(3) = 0 THEN O$ = "FIZZ"
50  IF  FN M(5) = 0 THEN O$ = O$ + "BUZZ"
60  IF O$ = "" THEN O$ =  STR$ (A)
70  PRINT O$
80  NEXT A

ASIC[edit]

REM FizzBuzz
CLS
FOR I = 1 TO 100
  IMOD15 = I MOD 15
  IF IMOD15 = 0 THEN
    PRINT "FizzBuzz"
  ELSE 
    IMOD5 = I MOD 5 
    IF IMOD5 = 0 THEN
      PRINT "Buzz"
    ELSE
      IMOD3 = I MOD 3
      IF IMOD3 = 0 THEN
        PRINT "Fizz"
      ELSE
        PRINT I
      ENDIF
    ENDIF
  ENDIF
  
  REM ASIC uses only 25 screen lines. 
  REM After the 25th line, printing starts from the top.
  REM So...
  C = CSRLIN
  IF C > 20 THEN
    PRINT "<Press a key to continue>"
    LOOP: 
      X$=INKEY$
      IF X$="" THEN LOOP:
    CLS
  ENDIF
NEXT I
END

BaCon[edit]

' FizzBuzz
FOR i = 1 TO 100
    msg$ = IIF$(MOD(i, 3), "", "Fizz")
    msg$ = msg$ & IIF$(MOD(i, 5), "", "Buzz")
    PRINT IIF$(msg$ = "", STR$(i), msg$), " ";
NEXT
PRINT
Output:
prompt$ ./fizzbuzz | fold -w 72 -s
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19
Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz 31 32 Fizz 34 Buzz
Fizz 37 38 Fizz Buzz 41 Fizz 43 44 FizzBuzz 46 47 Fizz 49 Buzz Fizz 52
53 Fizz Buzz 56 Fizz 58 59 FizzBuzz 61 62 Fizz 64 Buzz Fizz 67 68 Fizz
Buzz 71 Fizz 73 74 FizzBuzz 76 77 Fizz 79 Buzz Fizz 82 83 Fizz Buzz 86
Fizz 88 89 FizzBuzz 91 92 Fizz 94 Buzz Fizz 97 98 Fizz Buzz

BASIC[edit]

Works with: QuickBasic version 4.5

If/else ladder approach[edit]

FOR A = 1 TO 100
   IF A MOD 15 = 0 THEN
      PRINT "FizzBuzz"
   ELSE IF A MOD 3 = 0 THEN
      PRINT "Fizz"
   ELSE IF A MOD 5 = 0 THEN
      PRINT "Buzz"
   ELSE
      PRINT A
   END IF
NEXT A


Concatenation approach[edit]

FOR A = 1 TO 100
   OUT$ = ""

   IF A MOD 3 = 0 THEN 
      OUT$ = "Fizz"
   END IF

   IF A MOD 5 = 0 THEN
      OUT$ = OUT$ + "Buzz"
   END IF
   
   IF OUT$ = "" THEN
      OUT$ = STR$(A)
   END IF

   PRINT OUT$
NEXT A

See also: RapidQ

Basic09[edit]

PROCEDURE FizzBuzz
DIM n:INTEGER

FOR n=1 to 100
  IF MOD(n,15)=0 THEN
    PRINT "FizzBuzz"
  ELSE
    IF MOD(n,3)=0 THEN
      PRINT "Fizz"
    ELSE
      IF MOD(0,5)=0 THEN
        PRINT "Buzz"
      ELSE
        PRINT n
      ENDIF
    ENDIF
  ENDIF
NEXT n
END


BASIC256[edit]

for number = 1 to 100
	if number mod 15 = 0 then
		print "FizzBuzz"
	else
		if number mod 3 = 0 then
			print "Fizz"
		else
			if number mod 5 = 0 then
				print "Buzz"
			else
				print number
			end if
		end if
	end if
next number
end


BBC BASIC[edit]

      FOR number% = 1 TO 100
        CASE TRUE OF
          WHEN number% MOD 15 = 0: PRINT "FizzBuzz"
          WHEN number% MOD 3 = 0:  PRINT "Fizz"
          WHEN number% MOD 5 = 0:  PRINT "Buzz"
          OTHERWISE: PRINT ; number%
        ENDCASE
      NEXT number%

Casio BASIC[edit]

For 1A To 100 Step 1
MOD(A,15)B
MOD(A,3)C
MOD(A,5)D

B=0"FIZZBUZZ"
B=0Goto 1
C=0"BUZZ"
C=0Goto 1
D=0"FIZZ"
D=0Goto 1

A
Goto 1

Lbl 1
Next

Commodore BASIC[edit]

Works with: Commodore BASIC version 3.5
10 REM FIZZBUZZ
20 FOR I=1 TO 100
30 IF INT(I/15)*15=I THEN PRINT "FIZZBUZZ":GOTO 70
40 IF INT(I/3)*3=I THEN PRINT "FIZZ":GOTO 70
50 IF INT(I/5)*5=I THEN PRINT "BUZZ":GOTO 70
60 PRINT I
70 NEXT I
80 END

See also Minimal BASIC.

FreeBASIC[edit]

'FreeBASIC
Dim As ULong n

For n = 1 To 100

    If n Mod 15 = 0  Then
        Print "FizzBuzz"
    ElseIf n Mod 3 = 0 Then
        Print "Fizz"
    ElseIf n Mod 5 = 0 Then
        Print "Buzz"
    Else
        Print n
    End If

Next n

sleep

GW-BASIC[edit]

10 FOR N = 1 TO 100
20     OP$ = ""
30     IF N MOD 3 = 0 THEN OP$ = "Fizz"
40     IF N MOD 5 = 0 THEN OP$ = OP$ + "Buzz"
50     IF OP$ = "" THEN PRINT N ELSE PRINT OP$
60 NEXT N

IS-BASIC[edit]

100 PROGRAM "Fizzbuzz.bas"
110 FOR I=1 TO 100
120   IF MOD(I,15)=0 THEN
130     PRINT "FizzBuzz"
140   ELSE IF MOD(I,3)=0 THEN
150     PRINT "Fizz"
160   ELSE IF MOD(I,5)=0 THEN
170     PRINT "Buzz"
180   ELSE
190     PRINT I
200   END IF
210 NEXT

Liberty BASIC[edit]

for i = 1 to 100
    select case
        case i mod 15 = 0
            print "FizzBuzz"
        case i mod 3 = 0
            print "Fizz"
        case i mod 5 = 0
            print "Buzz"
        case else
            print i
    end select
next i

Minimal BASIC[edit]

Works with: Commodore BASIC version 3.5
Works with: Nascom ROM BASIC version 4.7
10 REM FizzBuzz
20 FOR I = 1 TO 100
30 IF INT(I/15)*15 <> I THEN 60
40 PRINT "FizzBuzz"
50 GOTO 130
60 IF INT(I/3)*3 <> I THEN 90
70 PRINT "Fizz"
80 GOTO 130
90 IF INT(I/5)*5 <> I THEN 120
100 PRINT "Buzz"
110 GOTO 130
120 PRINT I
130 NEXT I
140 END

PureBasic[edit]

OpenConsole()
For x = 1 To 100
  If x%15 = 0
    PrintN("FizzBuzz")
  ElseIf x%3 = 0
    PrintN("Fizz")
  ElseIf x%5 = 0
    PrintN("Buzz")
  Else
    PrintN(Str(x))
  EndIf
Next
Input()

REALbasic[edit]

  For i As Integer = 1 To 100
    If i mod 3 = 0 And i mod 5 = 0 Then
      Print("FizzBuzz")
    ElseIf i mod 3 = 0 Then
      Print("Fizz")
    ElseIf i mod 5 = 0 Then
      Print("Buzz")
    Else
      Print(Str(i))
    End If
  Next

An alternative syntax:

  For i As Integer = 1 To 100
    Select Case True
      Case i mod 3 = 0 And i mod 5 = 0
      Print("FizzBuzz")
    Case i mod 3 = 0
      Print("Fizz")
    Case i mod 5 = 0
      Print("Buzz")
    Else
      Print(Str(i))
    End Select
  Next

Run BASIC[edit]

for i = 1 to 100
 print i;
 if (i mod 15) = 0 then print " FizzBuzz";
 if (i mod  3) = 0 then print " Fizz";
 if (i mod  5) = 0 then print " Buzz";
 print
next i

tbas[edit]

FOR i = 1 TO 100
	LET SHOW$ = ""
	IF MOD(i,3) = 0 THEN
		LET SHOW$ = SHOW$ + "Fizz"
	END IF
	IF MOD(i,5) = 0 THEN
		LET SHOW$ = SHOW$ + "Buzz"
	END IF
	IF SHOW$ = "" THEN
		LET SHOW$ = STR$(i)
	END IF
		
	PRINT SHOW$;" ";
NEXT

TI-83 BASIC[edit]

PROGRAM:FIZZBUZZ
For(I,1,100
I
If not(fPart(I/3
"FIZZ
If not(fPart(I/5
"BUZZ
If not(fPart(I/15
"FIZZBUZZ
Disp Ans
:End

TI-99/4a TI BASIC[edit]

10 REM **FIZZBUZZ IN TI-BASIC**
20 FOR I = 1 TO 100
30 IF ((I/15)-INT(I/15))=0 THEN 120
40 IF ((I/3)-INT(I/3))=0 THEN 80
50 IF ((I/5)-INT(I/5))=0 THEN 100
60 PRINT I
70 GOTO 140
80 PRINT "FIZZ"
90 GOTO 140
100 PRINT "BUZZ"
110 GOTO 140
120 PRINT "FIZZBUZZ"
130 GOTO 140
140 NEXT I
150 END

Tiny BASIC[edit]

    LET I=1
10  IF (I/15)*15<>I THEN GOTO 20 
    PRINT "FizzBuzz"
    GOTO 100
20  IF (I/3)*3<>I THEN GOTO 30 
    PRINT "Fizz"
    GOTO 100
30  IF (I/5)*5<>I THEN GOTO 40 
    PRINT "Buzz"
    GOTO 100
40  PRINT I
100 LET I=I+1
    IF I<=100 THEN GOTO 10
    END

True BASIC[edit]

FOR number = 1 TO 100
    IF MOD(number, 15) = 0 then
       PRINT "FizzBuzz"
    ELSEIF MOD(number, 3) = 0 then
       PRINT "Fizz"
    ELSEIF MOD(number, 5) = 0 then
       PRINT "Buzz"
    ELSE
       PRINT number
    END IF
NEXT number
END


Visual Basic .NET[edit]

Platform: .NET

Works with: Visual Basic .NET version 9.0+
Sub Main()
 
    For i = 1 To 100
        If i Mod 15 = 0 Then
            Console.WriteLine("FizzBuzz")
        ElseIf i Mod 5 = 0 Then
            Console.WriteLine("Buzz")
        ElseIf i Mod 3 = 0 Then
            Console.WriteLine("Fizz")
        Else
            Console.WriteLine(i)
        End If
    Next
 
End Sub

XBasic[edit]

Works with: Windows XBasic
PROGRAM "fizzbuzz"
VERSION "0.0001"

DECLARE FUNCTION Entry()

FUNCTION Entry()
  FOR i% = 1 TO 100
    SELECT CASE TRUE
      CASE i% MOD 15 = 0:
        PRINT "FizzBuzz"
      CASE i% MOD 3 = 0:
        PRINT "Fizz"
      CASE i% MOD 5 = 0:
        PRINT "Buzz"
      CASE ELSE:
        PRINT i%
    END SELECT
  NEXT i%
END FUNCTION

END PROGRAM


Yabasic[edit]

for number = 1 to 100
    if mod(number, 15) = 0 then 
        print "FizzBuzz"
    elsif mod(number, 3) = 0 then 
        print "Fizz"
    elsif mod(number, 5) = 0 then 
        print "Buzz"
    else 
        print number
    endif
next number
end