1) What is the main purpose of a for loop? a) To repeat a block of code a specific number of times b) To wait for a condition to become true c) To execute code only once d) To handle button input in Arduino 2) What is i called in a for loop? a) A function b) An index c) A data type d) A conditional operator 3) In a for loop, what does i = 0 do?  a) It ends the loop b) It checks if i equals 0 c) It sets the starting value of i to 0 d) It increases i by 1 4) In a for loop, what does i < 5 do?  a) It checks if i is less than 5 before each loop iteration b) It assigns the value 5 to i c) It increases i by 5 each time d) It ends the loop when i is greater than 5 5) What does i++ mean inside a for loop? a) Stops the loop b) Increments i by 1 each time c) Resets i to 0 d) Skips even numbers 6) What is the correct syntax for a for loop that repeats 5 times? a) for (int i=1; i<=5; i++) b) for (i=0; i<5; i--) c) for (int i=0; i<5; i++) d) for (int i=5; i>0; i++) 7) How many times will this loop run? a) 3 b) 4 c) 5 d) 0 8) What does the following loop do? a) Prints 1, 2, 3 b) Prints 0, 1, 2 c) Prints 0, 1, 2, 3 d) Prints nothing 9) What is the main purpose of a while loop? a) To repeat a block of code a fixed number of times b) To execute code until a condition is false c) To create recursive functions d) To define functions 10) What is the correct syntax for a while loop? a) b) c) d) 11) When is a while loop most useful? a) When the number of repetitions is known ahead of time b) When you want to delay your program c) When you don’t know how many times the loop will run d) When using the loop() function in Arduino 12) What happens if you forget to include i++ inside a while loop that uses i as a counter? a) The loop will run only once b) The loop will never start c) The loop may become infinite because the condition never changes d) The loop will skip some iterations 13) What is required to prevent an infinite loop in this code? a) Change i to a float b) Use a for loop instead c) Add i++; inside the loop d) Use i = 5 at the start 14) What is a potential downside of using a while(true) infinite loop without a proper exit condition in embedded systems like Arduino? a) It ensures the program runs forever safely b) It can cause the microcontroller to freeze or become unresponsive c) It reduces power consumption d) It simplifies code debugging 15) What would be the output of this code? a) b) c) d) D. Nothing prints

Leaderboard

Visual style

Options

Switch template

Continue editing: ?