Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3488840
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:19:14+00:00 2026-05-18T11:19:14+00:00

I have 2 parts of code I want to execute. Both are conditionals if

  • 0

I have 2 parts of code I want to execute. Both are conditionals

if Value1 < N do something 

else if Value1 >= N do something

if Value2 < N do something 

else if Value2 >= N do something

I want at one statement of each to execute.

How does the if work in erlang? there is no else. I use multiple guards, but that looks like I have 4 if statements. in groups of 2.

if some condition   
code;

if other condition  
code

end.

I get a syntax error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:19:15+00:00Added an answer on May 18, 2026 at 11:19 am

    The form for an if is:

    if
        <guard 1> -> <body1> ;
        <guard 2> -> <body2> ;
        ...
    end
    

    It works trying the guards in if-clauses in top-down order (this is defined) until it reaches a test which succeeds, then the body of that clause is evaluated and the if expression returns the value of the last expression in the body. So the else bit in other languages is baked into it. If none of the guards succeeds then an if_clause error is generated. A common catch-all guard is just true which always succeeds, but a catch-all can be anything which is true.

    The form for a case is:

    case <expr> of
        <pat 1> -> <body1> ;
        <pat 2> -> <body2> ;
        ...
    end
    

    It works by first evaluating and then trying to match that value with patterns in the case-clauses in op-down order (this is defined) until one matches, then the body of that clause is
    evaluated and the case expression returns the value last expression in the body. If no pattern matches then a case_clause error is generated.

    Note that if and case are both expressions (everything is an expression) so they both must return values. That is one reason why there is no default value if nothing succeeds/matches. Also to force you to cover all options; this is especially important for case. if is just a degenerate case of case so it inherited it. There is a bit of history of if in the Erlang Rationale which you can find on trapexit.org under user contributions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTML source code in one String . I want to get
I have third-party C code that writes data to a file. I want to
I have some parts in my code that look like this: A, B and
I have the code block below, I deleted all unnecessary parts, just left the
I'm stuck on one thing i can't get solved. I have part of code,
I have two text boxes and I want skip a block of code only
I have been learning Tkinter, i have written a small code where i want
I have part of the code below: while($array = $result->fetch_assoc() ){ $second_query = INSERT
I have this part of code in my functions.php: function cc_admin_enqueue_scripts($hook) { $file_dir=get_bloginfo('template_directory'); wp_enqueue_script('media-upload');
i have this simple question please. I have this part of code which sets

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.