How can I implement loop in plt-scheme like in java-
for(int i=0;i<10;){
for(int j=0;j<3;){
System.out.println(\"\"+j);
j++;
The iteration construct in Scheme is "do
", you can look it up in the R5RS specification.
The example you gave would look something like this:
(do ((i 0 (+ i 1))) ((> i 9))
(do ((j 0 (+ j 1))) ((> j 2))
(display j)
(newline))
(display i)
(newline))
(do ...)
is a bit more general than what shows up in this example. You can for example make it return a value instead of just using it for its side effects. It is also possible to have many "counters":
(do ((i 0 (+ i 1)
(j 0 (+ j 2))
((stop? i j) )
exprs...)