IF-Else & Nested IF-Else conditional statement in React Native example

IF-Else is a type of conditional statement which executes a part of code based on condition. The condition can be anything with different type of operators. So in this tutorial we would going to create a react native application with IF-Else & Nested IF-Else conditional statement for both android and iOS applications. So let’s get started .

IF-Else Syntax :

Nested IF-Else Syntax :

Contents in this project IF-Else & Nested IF-Else conditional statement in React Native Android iOS App tutorial:

1. Import StyleSheet, View, Button, TextInput and Alert component in your project.

2. Create constructor() in your project. Now we would make a State named as TextInputValue, which is used to store TextInput inside typed value.

3. Create a function named as Simple_If_Else(). Inside this function we would simply use the normal If-Else condition checking that entered value is equals-equals(==) to 1, If the condition is true then it will simply print a Alert message on screen and If the condition is false then it will show alert message that value is not found.

4. Create a function named as Nested_If_Else(). Inside this function we would the nested if conditional statement which is used to check multiple conditions using single IF-Else code.

5. Create a Root View in render’s return block.

6. Create 1 TextInput and 2 Button components in root view.

7. Create Style.

8. Complete source code for App.js File :

Screenshots :

IF-Else