Switch case and if

Source: Internet
Author: User
Tags case statement switch case

Case

The switch case statement is occasionally used in programming, and there are two errors in the handling of case statements, which are summarized as follows:

1 case must be constant, cannot use ' < ' or ' > ' This logical operation after 2 case if ' | | ' or ' && ' logical operation, then the actual is 1 or 0#include <iostream>using namespace std;int main (int argc, char * argv[]) {    int i;< c1/>cin>>i;    switch (i)    {case        :            cout<<i<<endl;            break;        Case ' a ':            cout<<i<<endl;            break;        Default:            cout<< "Hello" <<endl;    }    return 0;}

  

If

There are two main errors that can occur during programming using the IF process:

1Determine logical errors, such as if (i=0)2 ifElseIf ElseIf only executes one if or one does not perform # include<iostream>using namespacestd;intMainintargcChar*argv[]) {    inti; CIN>>i; if(i==1) cout<<i<<Endl; Else if(i>0) cout<<i+1<<Endl; Else if(i==0) cout<<i<<Endl; return 0;}

Switch case and if

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.