Can a recursive function have iterations/loops?
Posted
by
Omega
on Programmers
See other posts from Programmers
or by Omega
Published on 2012-10-26T17:54:51Z
Indexed on
2012/10/26
23:16 UTC
Read the original article
Hit count: 356
I've been studying about recursive functions, and apparently, they're functions that call themselves, and don't use iterations/loops (otherwise it wouldn't be a recursive function).
However, while surfing the web for examples (the 8-queens-recursive problem), I found this function:
private boolean placeQueen(int rows, int queens, int n) {
boolean result = false;
if (row < n) {
while ((queens[row] < n - 1) && !result) {
queens[row]++;
if (verify(row,queens,n)) {
ok = placeQueen(row + 1,queens,n);
}
}
if (!result) {
queens[row] = -1;
}
}else{
result = true;
}
return result;
}
There is a while
loop involved.
... so I'm a bit lost now. Can I use loops or not?
© Programmers or respective owner