if

Last updated

What is if?

To use if in Kotlin, add the condition to check within parentheses () and the action to take if the result is true within curly braces {}. You can use else and else if for additional branches and checks.

Also, you can also write if as an expression, which lets you assign its returned value directly to a variable. In this form, an else branch is required. The if expression serves the same purpose as the ternary operator (condition ? then : else) found in other languages.

Free resources to learn if

More in stage 12: Conditional Expressions

if: common questions

Can I learn if in Hindi?

This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain if in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.

Is this if tutorial for beginners?

It is lesson 38 of 153 in the free Kotlin roadmap, in stage 12, Conditional Expressions. If you are new to Kotlin, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.

Still confused? Ask me