HomeCode HereJava control flow quiz Java control flow quiz Admin 1 min read Updated November 16, 2026 Nine questions on if, switch, loops and arrays. Java Java control flow quiz 9 questions, instant feedback Question 1 of 9 Which condition is valid in an if statement? A if (count) B if (count = 1) C if (count == 1) D if count == 1 Java requires a boolean expression in parentheses. An int does not convert to boolean, and = is assignment. Question 2 of 9 What does else if allow? A Several exclusive branches B A loop C A method call D An exception Each else if is checked only when the previous conditions were false, which makes the branches exclusive. Question 3 of 9 Which switch type is allowed in modern Java? A String B double C boolean D Any object switch works with integers, enums, strings and a few other types, but not double or boolean. Question 4 of 9 What happens when a switch case has no break? A A compile error B Execution falls through to the next case C The switch exits D The default runs Without break, control continues into the following case. Arrow-style switch avoids the problem. Question 5 of 9 How many times does for (int i = 0; i < 3; i++) run? A 2 B 3 C 4 D Forever i takes the values 0, 1 and 2, so the body runs three times. Question 6 of 9 What is the difference between while and do-while? A do-while checks the condition after the body B while runs at least once C There is none D do-while cannot use break A do-while body always runs once, because the condition is tested at the end. Question 7 of 9 What does an array of int default to when created with new int[5]? A null B 0 C Random values D A compile error Array elements are initialised to the type's default: 0 for int, false for boolean, null for objects. Question 8 of 9 What is the valid index range for new int[4]? A 1 to 4 B 0 to 4 C 0 to 3 D 1 to 3 Java arrays are zero-indexed, so four elements are at indexes 0, 1, 2 and 3. Index 4 throws. Question 9 of 9 Which loop is best when the number of items is known? A while B do-while C for D switch A for loop puts the counter's start, condition and step in one line, which reads well for a known count. Check my answers Try again Your answers stay in this browser. Nothing is sent to a server. More quizzes Java final quiz 10 questions Java getting started quiz Coming soon Java methods and objects quiz 9 questions All quizzes