A switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type. For instance, rather than the code
if (x == 1)
printf(“x is equal to one.\n”);
else if (x == 2)
printf(“x is equal to two.\n”);
else if (x == 3)
printf(“x is equal to three.\n”);
printf(“x is not equal to one, two, or three.\n”);
the following code is easier to read and maintain
case 1: printf(“x is equal to one.\n”);
case 2: printf(“x is equal to two.\n”);
case 3: printf(“x is equal to three.\n”);
default: printf(“x is not equal to one, two, or three.\n”);
There is no such rule.
but only comfort and ease of coding matters.
functionally, both are same if they are used as per their exact syntax.
but in switch, you can program in such a way that, multiple cases carry the same body.
it all depends on the situation to decide which one would be better.
-------------------------------------------- Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
One rule is of course the fact that switch-case needs to compare with constant values; you cannot put a variable in a case statement.
If you have constant values to compare with, and the range is rather small, the compiler is often able to generate a jump table which is faster in comparison.
However, if you have a large range of values and/or if they are widely spread, many compilers would generate the code as if you would have used the if-else solution. To create a jump table in such case would be far too complex to be built with a generic algorithm as a compiler would provide.
If you opt for the if-else solution, put the condition most likely to happen at the top, otherwise multiple conditions have to be evaluated before the right one is found for the major part of the calls.
if there are only two state for a condition you can use ternary operator or if-else
For more than two and something that can be handled in a few if-else blocks you can use if-else
if there are a huge number of cases use switch-case
But if you are operating on strings if-else would be the choice as switch-case won't work
You need to google first, if you have "It's urgent please" mentioned in your question. _AnShUmAn_
Although you are satified with all answers i want to mangle in the discussion. To my opinion If and Case are very different because:
where <condition> is ANY expression that results in true or false, while the Case can only be a constant (from the same datatype as the variable named in the switch). As you see possible values of a variable as a domain then a Case construct is more like a domain-checker...
There are many if constructs that can not be rewritten to a Case construct. But all Case constructs can be rewritten to If-constructs, although performance can/will be worse. See the Case construct of a specialized version of If, losing some flexibility but gaining some performance...
Can I make a suggestion - rather than using whatever you are using to try and automate Outlook, use #import to do automation in C++ - it's the simplest and easiest way. Here's how I automate Excel 2007 (getting the active workbook name in this case) - automating Outlook just requires you to determine Outlook's libid (which, from the OLE COM object viewer, is 00062FFF-0000-0000-C000-000000000046):
#import "libid:00020813-0000-0000-C000-000000000046" version("1.6") auto_search no_dual_interfaces rename("DialogBox", "excelDialogBox") rename("RGB", "excelRGB") rename("DocumentProperties", "excelDocumentProperties") rename("SearchPath", "excelSearchPath") rename("CopyFile", "excelCopyFile") rename("ReplaceText", "excelReplaceText")
// Ensure the Excel::_ApplicationPtr is destructed before we uninitialize COM.
std::cout << "Getting name\n";
std::cout << xl->ActiveWorkbook->FullName << std::endl;
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
You want to make something that doesn't have any sense ?
Do you know what a character and what a character string are ? Why do you want to store an array of characters into a single character ? This doesn't make any sense at all. Do you want to use a char* instead ? If yes, as already told you a lot of times before, read the article that Rajesh suggested. Why do you keep asking the same type of questions again and again instead of trynig to understand the concept ?
I think this is a lost cause. If I remember well, he has been suggested to read the articles a couple of times already. Some people still thinkks that it is far more efficient to ask everything on a forum rather to learn something
I see the OP has a LOT of reading to do, but if he won't, that would be the least of our interest (besides the fact that he posts the same stuff repeatedly and irritates). We can only suggest him what should he do.
Looks like a lost cause though.
It is a crappy thing, but it's life -^Carlo Pallini
My problem is to set TO address for a mail using Mapi in C++ i able to set BOdy and Subject and from adress iam unable to set TO adresss here is my core Logic
prop.Value.lpszW= _T("this is Subject");
prop.Value.lpszW=_T("Body for a application");
//problem here it is not setting the value to TO adress