What must the condition be to execute the statement? What happens if the condition is false?
TRUE. It skips the statement.
When does a for loop end?
When a false is encountered in the loop.
Both the if and the else get a condition to execute. True or False?
False, the else doesn't get a condition.
What is a sentinel value?
A specific value that will stop your loop.
What is short-circuiting?
Once a true is found, immediately goes to statement.
What does 'if (x != sum)' mean?
x does not equal sum.
What is the order (steps 1-4) of the for loop?
1. initialization
2. condition
3. body
4. increment
What does the nested if statement print?
int value = 6
if (value >= 0)
if (value%2 = 0)
s.o.p ("Dog");
else
s.o.p ("Cat");
Dog
If the condition of the loop never becomes false and the loop goes on forever, what is it called?
An infinite loop.
What is the increment and decrement operator?
The increment operator adds 1 to the value (++) and the decrement operator subtracts 1 from the value (--).
What is the '&&' operator and what does it do? What about '||'? And what about '!'?
&& is the AND operator and means that everything in the condition must be true. || is the OR operator and means that only one part of the condition must to be true. ! is the NOT operator and means the value does not equal something.
What is the difference between a for loop and a while loop?
For loop: If we know how many times we want to execute the loop (count control).
While loop: When we don't know how many times we'll go through the loop.
What are the relational operators?
== equal to
!= not equal to
< less than
<= less than or equal to
> greater than
>= greater than or equal to
Is the code correct? If not, find the errors and fix them.
int x = 10
while (x>5)
s.o.p (x/0)
No. Cannot divide by 0.
int x = 10
while (x>5)
s.o.p (x/2); //or change output overall
Rewrite this condition.
if !(x=3 || !(x>5 && x<=0))
if (x!=3 && (x<=5 || x>0))
What does this code do?
int x=1
while (x<5)
{ s.o.p (x);
x--;
}
Prints x and subtracts 1 until x equals 4.
Create a for loop that print odd numbers from 1 to 99.
for (int x=1; x<100; x+2) OR
for (int x=1; x<=99; x+2)
s.o.p (x);