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

  • Home
  • SEARCH
  • 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 7429565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:59:21+00:00 2026-05-29T08:59:21+00:00

And does each expression in the else if must test the same variable ?

  • 0

And does each expression in the else if must test the same variable ? Please give example for the second question.
And can any expression be used for the IF expression ?
And in SWITCH statement, each case can have only one statement or more ? If we can put more than 1 statement, then what is the syntax for it ?

case 1:
      printf("Blah Blah");
      printf("Blah blah blah");

Or

case 1:
      {
      printf("Blah Blah");
      printf("Blah blah blah");
      }

Yes these are all silly question’s but I am still learning programming.
Thanks in advance.

  • 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-29T08:59:22+00:00Added an answer on May 29, 2026 at 8:59 am

    if, else, “else if”

    An if can have zero or one associated else clauses. Examples:

    if (X)
        printf("if\n");
    

    or

    if (X)
        printf("if\n");
    else
        printf("else\n");
    

    These take only a single statement. If you want to use multiple statements (and some people say it’s better to do this even if you only have one statement per if/else), you have to use curly braces, like this:

    if (X) {
        printf("if\n");
    } else {
        printf("else\n");
    }
    

    You can also nest ifs:

    if (X)
        printf("X\n");
    else
        if (Y)
            printf("Y\n");
        else
            printf("something else\n");
    

    This is usually written in a more readable way, though:

    if (X)
        printf("X\n");
    else if (Y)
        printf("Y\n");
    else
        printf("something else\n");
    

    You see, the else if is nothing special, it’s just another form of laying out a nested if.

    Again, if you want more than one statement in there, you need to use curly braces:

    if (X) {
        printf("X\n");
        printf("X2\n");
    } else if (Y) {
        printf("Y\n");
        printf("Y2\n");
    } else {
        printf("something else\n");
        printf("yet another print\n");
    }
    

    switch/case

    As for switch statements, there you don’t need curly braces. Note however that “cases fall through” which means that in this example all four printfs are actually executed:

    switch (1) {
      case 1:
        printf("I will be printed!\n");
        printf("Me too!\n");
      case 2:
        printf("And me also! (although I probably shouldn't)\n");
      case 3:
        printf("Me as well!\n");
    }
    

    If you don’t want this (which is usually the case), you have to use an explicit break after the code in each case:

    switch (1) {
      case 1:
        printf("I will be printed!\n");
        printf("Me too!\n");
        break;
      case 2:
        printf("I won't :(\n");
        break;
      case 3:
        printf("D'oh!\n");
        break;
    }
    

    Blocks

    By the way, the curly braces rule can be generalized: At every place where a single statement is allowed, you can also use something like { ... }, which is called a block. The advantage of using blocks is that you can

    1. Use multiple statements where only one would be allowed otherwise (e.g. in an if)
    2. Declare variables at the beginning of every block! Thus, you can do something like the following case 3: { int x = 3; printf("%d\n", x); }.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have any ideas on if/how one could create a regular expression to
My Questions is Is there any regular expression engine that does Just-In-Time compiling during
This is my second question about this topic, the original question can be found
What does each expression evaluate to? Assume x is 2 before each one. int
Does each column of a table in SQL Server have a unique id? I've
Why does tempuri.org exist? Why does each XML Webservice require its own namespace, unique
How could I execute a set of .SQL files (each does some data transformations)
I've made a small program which has 2 buttons and each does certain thing.
i have a table (System.Web.UI.WebControls). each row does have three cells. in cells' controls
I have a scenario when I start 3..10 threads with ThreadPool. Each thread does

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.