Lec 7: Loops and Recursion Flashcards
What is the syntax of a do loop
do{
Statement(s);
} while (condition);
What are 2 examples of infinitely running loops?
for(; ; ){} and while(true){}
What does continue do in a loop?
Immediately ends that loop run and goes for a new run
What is the number of iterations for
for (int i = 1; i < n; n++){
//iteration
}
n - 1
True or false: Every recursive method must have a base case or a stopping condition
True
True or false: A recursive method is invoked differently from a non-recursive method
False
True or false: Every recursive method must have a return value
False
What error happens when a recursive method doesn’t eventually get to a solution?
StackOverFlow
In the following method, what is the base case?
static int xMethod(int n){
if (n==1){
return 1;
}else{
return n + xMethod(n-1)}
}
n == 1
True or false: Recursive methods take more memory space than non-recursive methods
True
True or false: recursive methods run faster than non-recursive methods
False
True or false: A recursive method can always be replaced by a non-recursive method
True