Loops/Break: Difference between revisions
< Loops
Content added Content deleted
(Created task with Java and BASIC) |
m (→{{header|BASIC}}: Added note about EXIT FOR) |
||
Line 6: | Line 6: | ||
a = int(rnd * 20) |
a = int(rnd * 20) |
||
print a |
print a |
||
if a = 10 then exit loop |
if a = 10 then exit loop 'EXIT FOR works the same inside FOR loops |
||
b = int(rnd * 20) |
b = int(rnd * 20) |
||
print b |
print b |
||
loop</lang> |
loop</lang> |
||
=={{header|Java}}== |
=={{header|Java}}== |
Revision as of 19:55, 5 June 2009
![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.
Show a while loop which prints two random numbers (newly generated each loop) from 0 to 19 (inclusive). If the first number is 10, print it, stop the loop, and do not generate the second. Otherwise, loop forever.
BASIC
<lang qbasic>do
a = int(rnd * 20) print a if a = 10 then exit loop 'EXIT FOR works the same inside FOR loops b = int(rnd * 20) print b
loop</lang>
Java
<lang java>while(true){
int a = (int)(Math.random()*20); System.out.println(a); if(a == 10) break; int b = (int)(Math.random()*20); System.out.println(b);
}</lang>