So, this time ,we will be continue about C++
In a control structure,there are three essential structure which are:
1.Sequential
2.Selection
3.Repetition
Sequential
- Carrying out statements in the order
- Default control structure unless the other control structures causes a change in the sequence
Selection
- One of several alternatives will be chosen based on a condition
- Execute the chosen alternative and skip the other alternative
So for this selection, there are if-statement,if -else statement and also switch statement. The example are shown as below:
The result will be like this. Then, you just have to enter the value , click the enter button and it will automatically determine the statement based on your code written just now.
Make sure the condition before inserting the symbol,based on the statement given.
It is important to remind that,for an expression like this:
0 ≤ n ≤ 100
we have to write them in this ways:
0<=n && n<=100
Repetition
- Repeats a section of code as long as a certain condition is true.
- 3 types of loop statement:
- while statement
- for statement
- do-while statement
Example of program using ‘while’statement:
Example of program using ‘for’statement:
So,here we can see how the ‘do-while’ statement is different to ‘while’statement.
That's it..Playing with codes and symbols, its quite tough, but don't worry,you guys will get through it soon. All the best!!See ya..
No comments:
Post a Comment