Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

The if-else Statement

Sumit Rawal answered on March 24, 2021 Popularity 5/10 Helpfulness 1/10

Contents


More Related Answers

  • javascript how to do else if
  • javascript if else
  • how to use if else statement in javascript
  • javascript how to do if else
  • javascript if/else
  • if condition
  • javascript if else
  • JavaScript if, else, and else if
  • IF..ELSE Statement
  • javascript if else
  • if else if
  • if else statement
  • else if
  • if else statement
  • if else javascript
  • Example of an IF..ELSE Statement
  • if else if else
  • if else functionr
  • if else
  • if else if

  • The if-else Statement

    0

    What if we want to execute a different set of operations in case an if condition turns out to be False?

    That is where the if-else statement comes into the picture.

    Structure

    The if-else statement looks something like this:

    svg viewer

    There’s nothing too tricky going on here. If the condition turns out to be False, the code after the else: keyword is executed.

    Hence, we can now perform two different actions based on the condition’s value.

    The else keyword will be on the same indentation level as the if keyword. Its body will be indented one tab to the right just like the if statement.

    Here’s the if-else statement in action: 

    Popularity 5/10 Helpfulness 1/10 Language python
    Source: Grepper
    Tags: python
    Link to this answer
    Share Copy Link
    Contributed on May 16 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10

    Closely Related Answers



    6
    Popularity 10/10 Helpfulness 4/10 Language java
    Source: Grepper
    Tags: java
    Link to this answer
    Share Copy Link
    Contributed on Apr 18 2022
    Mohamed Essam
    0 Answers  Avg Quality 2/10

    1
    Popularity 10/10 Helpfulness 4/10 Language javascript
    Source: Grepper
    Tags: javascript j
    Link to this answer
    Share Copy Link
    Contributed on Aug 23 2022
    Tender Trout
    0 Answers  Avg Quality 2/10

    9
    Popularity 9/10 Helpfulness 4/10 Language python
    Tags: python py
    Link to this answer
    Share Copy Link
    Contributed on Jun 14 2022
    Wookie
    0 Answers  Avg Quality 2/10

    2
    Popularity 9/10 Helpfulness 3/10 Language whatever
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on Jul 09 2022
    tricks llorente
    0 Answers  Avg Quality 2/10

    5
    Popularity 10/10 Helpfulness 3/10 Language javascript
    Source: Grepper
    Tags: javascript j
    Link to this answer
    Share Copy Link
    Contributed on Mar 24 2021
    Poor Platypus
    0 Answers  Avg Quality 2/10

    0
    Popularity 7/10 Helpfulness 3/10 Language whatever
    Tags: whatever
    Link to this answer
    Share Copy Link
    Contributed on Oct 20 2022
    tejaswara rao tavva
    0 Answers  Avg Quality 2/10

    0
    Popularity 8/10 Helpfulness 3/10 Language javascript
    Tags: javascript
    Link to this answer
    Share Copy Link
    Contributed on Aug 16 2023
    Hina Hina
    0 Answers  Avg Quality 2/10

    0
    Popularity 9/10 Helpfulness 2/10 Language javascript
    Source: Grepper
    Tags: javascript j
    Link to this answer
    Share Copy Link
    Contributed on Aug 16 2022
    madhav
    0 Answers  Avg Quality 2/10

    0
    Popularity 7/10 Helpfulness 2/10 Language javascript
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on Feb 01 2023
    Gifted Grivet
    0 Answers  Avg Quality 2/10

    0
    Popularity 9/10 Helpfulness 2/10 Language python
    Tags: python py
    Link to this answer
    Share Copy Link
    Contributed on May 16 2022
    Poor Peacock
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.