1. | What are the parts to a for loop declaration? | |
2. | What types of variables can be used for a switch statement? | |
3. | What is the purpose of the default statement in a switch statement? | |
4. | Why is it important to use the double equals sign in an if statement? | |
5. | Why might a switch statement be better than an if statement in some cases? | |
6. | What happens if you omit the break statements from your switch block? | |
7. | What is the purpose of a for loop? | |
8. | Can you have an if statement without enclosing brackets? | |
9. | How do you implement more than one choice in an if statement? | |
10. | What other possibilities besides equivalence can you use for if statements? | |
Answers
1. | • Declare and initialize the loop counter • Set the conditions under which the loop will execute • Increment the loop counter |
2. | Integer or character |
3. | To handle situations other than the case statements you define. In short, to handle anything that does not fit one of your defined case statements. |
4. | If you use a single equals, that is an assignment operator, and it will make your if statement always true, regardless of any user input. |
5. | If you have multiple selections (more than 2 or 3) |
6. | Then the next statement will also execute. |
7. | To execute a given code block a certain number of times |
8. | Yes, if there is only one line of code and it immediately follows the if statement. |
9. | With else statements |
10. | <= >=!= || && |