Jani rules for making program

Embed Size (px)

Citation preview

  1. 1. Rules for Programming We need simply three constructs to solve any problem. 1) Things should be executed sequentially. That means the statements are executed in a sequence i.e. the second statement follows the first and so on. 2) We need to have a decision. The decision means if something is true, the program executes it. Otherwise, it tries doing something else. So there is simple decision or ifelse decision. 3) The third construct is loop, which is a repetition structure that performs the same task repeatedly with different values. So the availability of sequences, decisions and loops can help us write any program. The code, we write, should be short and concise. It need to be self-contained and understandable. Comments should be placed liberally. The comments should explain the logic, not the mechanics. Try to avoid fancy programming. The indentation of the code has no means programmatically as it does not mean any thing at all. What actually matters is how you structure the code using braces and semicolons i.e. the structure of the language. Otherwise, C and C++ are free-format languages. We can write the whole code in a single line. But it will be very difficult to read. We format our code so that it could be read easily. So indentation is for us, not for the compiler. Similarly, any language does not dictate it. On the other hand, if we put our code inside braces and blocks, it will ensure a logical syntax.