Loops/While

From Rosetta Code
Revision as of 19:01, 11 April 2008 by rosettacode>Mwn3d (Created page with BASIC and Java)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Task
Loops/While
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

Works with: QuickBasic version 4.5

<qbasic>i = 1024 while i > 0

  print i
  i = i / 2

loop</qbasic>

Java

<java>int i = 1024; while(i > 0){

  System.out.println(i);
  i >>= 1; //also acceptable: i /= 2;

}</java>