ALGORITHM AND PROGRAMMING
On Wednesday, 10th October 2018, we were having a lecture in BINUS Anggrek auditorium. We continued learning about basic coding in C++.
For example, we learned about how to produce certain outputs, such as:
1. Ordered numbers from 1-10 or from different range
2. Operators, operands, and how do they work.
3. Showing square and triangle shapes.
4. Using repetition and selection.
5. Etc.
Many of case examples need selection and repetition functions.
Selection
To provide some conditions to be chosen for instructions.
There are 3 syntax for Selection:
For example, we learned about how to produce certain outputs, such as:
1. Ordered numbers from 1-10 or from different range
2. Operators, operands, and how do they work.
3. Showing square and triangle shapes.
4. Using repetition and selection.
5. Etc.
Selection and Repetition
Many of case examples need selection and repetition functions.
Selection
To provide some conditions to be chosen for instructions.
There are 3 syntax for Selection:
- IF (only shows statements for TRUE conditions)
- syntax: if(condition is TRUE){statements}
- IF-ELSE (shows statements for both TRUE and FALSE conditions)
- syntax: if(condition is TRUE){statements1} else if{statements2} else {statements3}
- SWITCH CASE (when many of nested IF-ELSE are going to be used, easier to read)
Repetition
To repeat certain instructions at a certain amount of time.
There are 3 Looping / Repetition operations:
- WHILE
- syntax: while(condition is still TRUE){do statements}
- DO-WHILE
- syntax: do{statements}while(condition is still TRUE);
- FOR
- syntax: (initialization; limitation; increment/decrement){statements}
Nested functions are also available for these functions.