How to resolve the algorithm Loops/While step by step in the BASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Loops/While step by step in the BASIC programming language
Table of Contents
Problem Statement
Start an integer value at 1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Loops/While step by step in the BASIC programming language
Source code in the basic programming language
100 LET I = 1024
110 DO WHILE I > 0
120 PRINT I
130 LET I = INT(I / 2)
140 LOOP
150 END
10 I% = 1024
20 IF I% > 0 THEN PRINT I%:I% = I% / 2: GOTO 20
REM Loops/While
I = 1024
WHILE I > 0
PRINT I
I = I / 2
WEND
END
i = 1024
WHILE i > 0
PRINT i
i = i / 2
WEND
int i = 1024;
while i > 0 {
io:println(i);
i = i / 2;
}
i = 1024
while i > 0
print i
i = i \ 2
end while
end
i% = 1024
WHILE i%
PRINT i%
i% DIV= 2
ENDWHILE
100 i = 1024
110 do while i > 0
120 print i
130 i = int(i/2)
140 loop
150 print
160 i = 1024
170 while i > 0
180 print i
190 i = int(i/2)
200 wend
10 N% = 1024
20 IF N% = 0 THEN 60
30 PRINT N%
40 N% = N%/2
50 GOTO 20
60 END
DEF X:INT
X=1024
OPENCONSOLE
WHILE X>0
PRINT X
X=X/2
ENDWHILE
'Output starts with 1024 and ends with 1.
'Putting the following in the loop will produce output starting with 512 and ending with 0:
'X=X/2
'PRINT X
PRINT:PRINT"Press any key to end."
'Keep console from closing right away so the figures can be read.
WHILE INKEY$="":ENDWHILE
CLOSECONSOLE
'Since this is, in fact, a Creative Basic console program.
END
' FB 1.05.0 Win64
Dim i As Integer = 1024
While i > 0
Print i
i Shr= 1
Wend
Sleep
window 1
long i = 1024
while i > 0
print i
i = int( i / 2 )
wend
HandleEvents
Public Sub Main()
Dim siCount As Short = 1024
While siCount > 0
Print siCount;;
siCount /= 2
Wend
End
10 I = 1024
20 WHILE I > 0
30 PRINT I
40 i = INT(i/2)
50 WEND
60 END
100 LET I=1024
110 DO WHILE I>0
120 PRINT I
130 LET I=IP(I/2)
140 LOOP
DEF X:INT
X=1024
OPENCONSOLE
WHILE X>0
PRINT X
X=X/2
ENDWHILE
'Output starts with 1024 and ends with 1.
'Putting the following in the loop will produce output starting with 512 and ending with 0:
'X=X/2
'PRINT X
'When compiled as a console only program, a press any key to continue message is automatic.
'I presume code is added by the compiler.
CLOSECONSOLE
'Since this is, in fact, an IWBASIC console program, which compiles and runs.
END
i = 1024
while i > 0
print i
i = int( i / 2)
wend
end
i = 1024
While i > 0
TextWindow.WriteLine(i)
i = Math.Floor(i / 2)
EndWhile
10 REM Loops/While
20 LET I = 1024
40 IF I <= 0 THEN 80
50 PRINT I
60 LET I = INT(I/2)
70 GOTO 40
80 END
10 I% = 1024
20 IF I% = 0 THEN END
30 PRINT I%
40 I% = I%/2 : rem INT(I/2)
50 GOTO 20
10 REM Loops/While
20 LET I=1024
30 IF I>0 THEN PRINT I:I=INT(I/2):GOTO 30
40 END
10 I=1024
20 IF I=0 THEN END
30 PRINT I
40 I=I/2
50 GOTO 20
If OpenConsole()
x.i = 1024
While x > 0
PrintN(Str(x))
x / 2
Wend
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
Input()
CloseConsole()
EndIf
Dim n As Integer
n = 1024
While n > 0
Print n
n = n \ 2
Wend
i = 1024
WHILE i > 0
PRINT i
i = INT(i / 2)
WEND
PRINT
i = 1024
DO WHILE i > 0
PRINT i
i = i \ 2
LOOP
END
i = 1024
WHILE i > 0
PRINT i
i = i \ 2
WEND
i = 1024
while i > 0
print i
i = int(i / 2)
wend
end
10 LET I=1024
20 IF I=0 THEN GOTO 60
30 PRINT I
40 LET I=INT (I/2)
50 GOTO 20
i = 1024
WHILE i > 0
PRINT i
i = i \ 2 ' Using \ for integer division instead of /
WEND
1024→I
While I>0
Disp I
I/2→I
End
Local i
1024 → i
While i > 0
Disp i
intDiv(i, 2) → i
EndWhile
10 REM Loops/While
20 LET I = 1024
30 IF I <= 0 THEN GOTO 70
40 PRINT I
50 LET I = I / 2
60 GOTO 30
70 END
LET i = 1024
DO WHILE i > 0
PRINT i
LET i = INT(i / 2)
LOOP
END
Public Sub LoopsWhile()
Dim value As Integer
value = 1024
Do While value > 0
Debug.Print value
value = value / 2
Loop
End Sub
Dim x = 1024
Do
Console.WriteLine(x)
x = x \ 2
Loop While x > 0
let number=1024
while number>0.5
print 1 number
let number=number/2
wend
end
i% = 1024
DO WHILE i% > 0
PRINT i%
i% = i% / 2
LOOP
i = 1024
while i > 0
Print i
i = int(i / 2)
wend
end
You may also check:How to resolve the algorithm Parametric polymorphism step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Sort a list of object identifiers step by step in the J programming language
You may also check:How to resolve the algorithm Pangram checker step by step in the Cowgol programming language
You may also check:How to resolve the algorithm Undefined values step by step in the 68000 Assembly programming language
You may also check:How to resolve the algorithm Averages/Mean angle step by step in the V (Vlang) programming language