Loop efficiency - C++ -


Initial question, on loop efficiency. I have started programming in C ++ (my first language) and using 'principles and practice using C ++' by Bjern Straffrup. I am making my way through the first chapters and have just introduced the concept of loops.

The first practice about the loop asks me the following questions: The character 'B' is four ('A' + 1), 'C' is four ('A' + 2), etc. To write a table of letters with their corresponding integer values:

A 97, B98, ..., z 122

However, I used uppercase, I created the following:

  integer number = 64; // For the integer value @ sign, the letter letter = number before one letter; // converts an integer alphabet to int i = 0; While (i & lt; = 25) {cout & lt; & Lt; ++ letter & lt; & Lt; "\ T" & lt; & Lt; ++ number & lt; & Lt; Endl; ++ i; }  

Should I have the goal to be present only in a 'loop' or what kind of change is not possible in between? I can not really think in any other way that the above version can be done in addition to the value of the character to be converted to its integer equivalent (i.e. the current method), or absolutely no conversion and letter collection '@' is not.

You should aim for clarity first and you should try to micro-optimize instead. You can better say that for loop:

  const int offsetToA = 65; Const int numberoffers = 26; For (int i = 0; i  

And you can convert between different types - which are called Casting ( static_cast in the code provided above).


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -