Loops/While: Difference between revisions
< Loops
Content added Content deleted
No edit summary |
m (→{{header|BASIC}}: Oops) |
||
Line 7: | Line 7: | ||
print i |
print i |
||
i = i / 2 |
i = i / 2 |
||
wend</qbasic> |
|||
=={{header|C}}== |
=={{header|C}}== |
Revision as of 02:59, 12 April 2008
Loops/While
You are encouraged to solve this task according to the task description, using any language you may know.
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
wend</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>