Loops/While: Difference between revisions
< Loops
Content added Content deleted
(Created page with BASIC and Java) |
No edit summary |
||
Line 8: | Line 8: | ||
i = i / 2 |
i = i / 2 |
||
loop</qbasic> |
loop</qbasic> |
||
=={{header|C}}== |
|||
<pre language="c">int i = 1024; |
|||
while(i > 0) { |
|||
printf("%d\n", i); |
|||
i /= 2; |
|||
}</pre> |
|||
=={{header|Java}}== |
=={{header|Java}}== |
||
<java>int i = 1024; |
<java>int i = 1024; |
Revision as of 21:35, 11 April 2008
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
Start a value at 1024. Loop while it is greater than 0. Print the value (with a newline) and divide it by two each time through the loop.
BASIC
<qbasic>i = 1024 while i > 0
print i i = i / 2
loop</qbasic>
C
int i = 1024; while(i > 0) { printf("%d\n", i); i /= 2; }
Java
<java>int i = 1024; while(i > 0){
System.out.println(i); i >>= 1; //also acceptable: i /= 2;
}</java>