Kotlin - Control Flow as ExpressionsWhich of the following is the correct syntax for assigning a value using if-else expression in Kotlin?Aval x = if (a > b) 10 else 20Bval x if (a > b) = 10 else = 20Cval x = if a > b then 10 else 20Dval x = if (a > b) { 10 } else { 20 } elseCheck Answer
Step-by-Step SolutionSolution:Step 1: Review Kotlin if-else expression syntaxThe correct syntax uses if(condition) value1 else value2 without extra keywords or misplaced braces.Step 2: Compare options with correct syntaxval x = if (a > b) 10 else 20 matches the correct syntax: val x = if (a > b) 10 else 20.Final Answer:val x = if (a > b) 10 else 20 -> Option AQuick Check:Correct if-else assignment syntax is val x = if (cond) val1 else val2 [OK]Quick Trick: Remember: if-else expression is inside assignment with = [OK]Common Mistakes:MISTAKESUsing 'then' keyword which Kotlin does not haveMisplacing equals signs around elseAdding extra else after braces
Master "Control Flow as Expressions" in Kotlin9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Kotlin Quizzes Collections Fundamentals - Destructuring in collection iteration - Quiz 13medium Data Types - Any type as universal base - Quiz 11easy Kotlin Basics and JVM Runtime - How Kotlin compiles to JVM bytecode - Quiz 6medium Loops and Ranges - Why ranges simplify iteration - Quiz 2easy Null Safety - Elvis operator (?:) for default values - Quiz 11easy Null Safety - Non-nullable types by default - Quiz 4medium Operators and Expressions - Equality (== structural vs === referential) - Quiz 8hard Variables and Type System - Val for immutable references - Quiz 10hard Variables and Type System - String templates and interpolation - Quiz 2easy Variables and Type System - String templates and interpolation - Quiz 4medium