FizzBuzz/Basic

From Rosetta Code
FizzBuzz/Basic is part of FizzBuzz. You may find other members of FizzBuzz at Category:FizzBuzz.

ANSI BASIC

Works with: Decimal BASIC
100 REM FizzBuzz
110 FOR Number = 1 TO 100
120    IF MOD(Number, 15) = 0 THEN
130       PRINT "FizzBuzz"
140    ELSEIF MOD(Number, 3) = 0 THEN
150       PRINT "Fizz"
160    ELSEIF MOD(Number, 5) = 0 THEN
170       PRINT "Buzz"
180    ELSE
190       PRINT Number
200    END IF
210 NEXT Number
220 END

Applesoft BASIC

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

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

' 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

Basic09

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

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

      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

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

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.

Chipmunk Basic

Works with: Chipmunk Basic version 3.6.4
Works with: QBasic
Works with: GW-BASIC
Works with: Just BASIC
Works with: MSX Basic

If/else ladder approach

10 cls
20 for n = 1 to 100
30   if n mod 15 = 0 then print "FizzBuzz" else if n mod 3 = 0 then print "Fizz" else if n mod 5 = 0 then print "Buzz" else print n
40 next n
50 end

Concatenation approach

10 cls
20 for n = 1 to 100
30   op$ = ""
40   if n mod 3 = 0 then op$ = "Fizz"
50   if n mod 5 = 0 then op$ = op$+"Buzz"
60   if op$ = "" then print n else print op$
70 next n
80 end

Craft Basic

Works with: Craft Basic
for i = 1 to 100

	if i % 15 = 0 then

		print "FizzBuzz"

	else

		if i % 3 = 0 then

			print "Fizz"

		else

			if i % 5 = 0  then

				print "Buzz"

			else

				print i

			endif

		endif

	endif

next i
Output:
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 

FreeBASIC

'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

FTCBASIC

rem uses carry command to perform modulus
rem uses flag variable for elseif structure

define i = 0, f = 0, r = 0

do

	let i = i + 1
	let f = 1

	let r = i / 15
	carry r

	if r = 0 then

		let f = 0
		print "FizzBuzz"

	endif

	let r = i / 3
	carry r

	if r = 0 and f = 1 then

		let f = 0
		print "Fizz"

	endif

	let r = i / 5
	carry r

	if r = 0 and f = 1 then

		let f = 0
		print "Buzz"

	endif

	if f = 1 then

		print i

	endif

loop i < 100

pause
end

GW-BASIC

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

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

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

Works with: Commodore BASIC version 3.5
Works with: MSX BASIC version all
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

MSX Basic

10 CLS
20 FOR N = 1 TO 100
30   IF N MOD 15 = 0 THEN PRINT "FizzBuzz" ELSE IF N MOD 3 = 0 THEN PRINT "Fizz" ELSE IF N MOD 5 = 0 THEN PRINT "Buzz" ELSE PRINT N
40 NEXT N
50 END

See also Minimal BASIC, Chipmunk Basic.

OxygenBasic

if/else ladder approach

uses console

int number
for number = 1 to 100
  if mod(number, 15) = 0 then 
    printl "FizzBuzz" 
  elseif mod(number, 3) = 0 then 
    printl "Fizz" 
  elseif mod(number, 5) = 0 then 
    printl "Buzz" 
  else 
    printl number
  endif
next number

printl cr "Enter..."
waitkey

Concatenation approach

uses console

int number
string op
for number = 1 to 100
    op = ""
    if mod(number, 3) = 0 then op = "Fizz"
    if mod(number, 5) = 0 then op = op & "Buzz"
    if op = "" then printl number else printl op
next number

printl cr "Enter..."
waitkey

Palo Alto Tiny BASIC

10 REM FIZZBUZZ
20 FOR I=1 TO 100
30 IF (I/15)*15=I PRINT "FIZZBUZZ";GOTO 70
40 IF (I/3)*3=I PRINT "FIZZ";GOTO 70
50 IF (I/5)*5=I PRINT "BUZZ";GOTO 70
60 PRINT I
70 NEXT I
80 STOP
Output:
      1
      2
FIZZ
      4
BUZZ
FIZZ
      7
      8
FIZZ
BUZZ
     11
FIZZ
     13
     14
FIZZBUZZ

...

     91
     92
FIZZ
     94
BUZZ
FIZZ
     97
     98
FIZZ
BUZZ

PureBasic

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()
CloseConsole()

QBasic

The QB64 solution works without any changes.

QB64

Works with: QBasic version 1.1
Works with: QuickBasic version 4.5

If/else ladder approach

For n = 1 To 100
    If n Mod 15 = 0 Then Print "FizzBuzz" Else If n Mod 3 = 0 Then Print "Fizz" Else If n Mod 5 = 0 Then Print "Buzz" Else Print n
Next n

Concatenation approach

For n = 1 To 100
    op$ = ""
    If n Mod 3 = 0 Then op$ = "Fizz"
    If n Mod 5 = 0 Then op$ = op$ + "Buzz"
    If op$ = "" Then Print n Else Print op$
Next n

QuickBASIC

Works with: QuickBasic version 4.5

If/else ladder approach

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

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

Quite BASIC

If/else ladder approach

10 CLS
20 FOR n = 1 TO 100
30   IF n % 15 = 0 THEN PRINT "FizzBuzz" ELSE IF n % 3 = 0 THEN PRINT "Fizz" ELSE IF n % 5 = 0 THEN PRINT "Buzz" ELSE PRINT n
40 NEXT n
50 END

Concatenation approach

10 CLS
20 FOR n = 1 TO 100
30   LET o$ = ""
40   IF n % 3 = 0 THEN LET o$ = "Fizz"
50   IF n % 5 = 0 THEN LET o$ = o$+"Buzz"
60   IF o$ = "" THEN PRINT n ELSE PRINT o$
70 NEXT n
80 END

REALbasic

  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

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

SmallBASIC

for ii = 1 to 100
  if(ii % 3 == 0 AND ii % 5 == 0)
    print "FizzBuzz"
  elseif(ii % 3 == 0)
    print "Fizz"
  elseif(ii % 5 == 0)
    print "Buzz"
  else
    print ii
  endif
next


tbas

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

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

10 DIM S$(3)
20 S$(1)="Fizz"
30 S$(2)="Buzz"
40 S$(3)="FizzBuzz"
50 FOR I = 1 TO 100
60 X=ABS((I/3=INT(I/3))+(I/5=INT(I/5))*2)
70 IF X=0 THEN 100
80 PRINT S$(X)
90 GOTO 110
100 PRINT I
110 NEXT I
120 END

TI-99/4a TI Extended BASIC

10 FOR I = 1 TO 100
20 IF I/3=INT(I/3) THEN PRINT "Fizz";
30 IF I/5=INT(I/5) THEN PRINT "Buzz";
40 IF I/3<>INT(I/3) AND I/5<>INT(I/5) THEN PRINT I;
50 PRINT
60 NEXT I

Tiny BASIC

    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

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

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

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

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