CloudFlare suffered a massive security issue affecting all of its customers, including Rosetta Code. All passwords not changed since February 19th 2017 have been expired, and session cookie longevity will be reduced until late March.--Michael Mol (talk) 05:15, 25 February 2017 (UTC)

FizzBuzz/Basic

From Rosetta Code
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
 

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

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 1→A To 100 Step 1↵
MOD(A,15)→B↵
MOD(A,3)→C↵
MOD(A,5)→D↵

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

A◢
Goto 1

Lbl 1↵
Next

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
 

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


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

Ring[edit]

 
for n = 1 to 20
if n % 15 = 0 see "" + n + " = " + "FizzBuzz" + nl loop
but n % 3 = 0 see "" + n + " = " + "Fizz"+ nl
but n % 5 = 0 see "" + n + " = " + "Buzz" + nl
else see "" + n + " = " + n + nl ok
next
 

Output:

1 = 1
2 = 2
3 = Fizz
4 = 4
5 = Buzz
6 = Fizz
7 = 7
8 = 8
9 = Fizz
10 = Buzz
11 = 11
12 = Fizz
13 = 13
14 = 14
15 = FizzBuzz
16 = 16
17 = 17
18 = Fizz
19 = 19
20 = Buzz

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

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

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