Assignment week 4
ITSB
Syafif Azmi Lontoh (52250060)
Student Major in Data Science
| ID | Name | Age | Salary | Position | Performance |
|---|---|---|---|---|---|
| 1 | Bagas | 25 | 5000 | Staff | Good |
| 2 | Joan | 30 | 7000 | Supervisor | Very Good |
| 3 | Alya | 27 | 6500 | Staff | Average |
| 4 | Dwi | 35 | 10000 | Manager | Good |
| 5 | Nabil | 40 | 12000 | Director | Very Good |
1 Conditional Statment
Conditional statements are fundamental constructs in programming that control the flow of execution based on specific conditions. They enable decision-making by allowing different blocks of code to execute depending on whether a condition evaluates to true or false. These statements are essential for creating dynamic and interactive programs. Determine bonus levels based on employee performance:
- Very Good → 20% of salary
- Good → 10% of salary
- Average → 5% of salary
Your Task: Write a program in R to calculate each employee’s bonus.
| ID | Name | Salary | Performance | Bonus |
|---|---|---|---|---|
| 1 | Bagas | 5000 | Good | 500 |
| 2 | Joan | 7000 | Very Good | 1400 |
| 3 | Alya | 6500 | Average | 325 |
| 4 | Dwi | 10000 | Good | 1000 |
| 5 | Nabil | 12000 | Very Good | 2400 |
2 Loops (For & While)
Loops, are used when we need to execute a block of code repetitively. Loops in programming are control flow structures that enable the repeated execution of a set of instructions or code block as long as a specified condition is met. Loops are fundamental to the concept of iteration in programming, enhancing code efficiency, readability and promoting the reuse of code logic.
2.1 For Loop
For loop in programming is a control flow structure that iterates over a sequence of elements, such as a range of numbers, items in a list, or characters in a string. The loop is entry-controlled because it determines the number of iterations before entering the loop.
| Name | Salary |
|---|---|
| Joan | 7000 |
| Alya | 6500 |
| Dwi | 10000 |
| Nabil | 12000 |
2.2 While Loop
A while loop in programming is an entry-controlled control flow structure that repeatedly executes a block of code as long as a specified condition is true. The loop continues to iterate while the condition remains true, and it terminates once the condition evaluates to false.
## Employee: Bagas | Position: Staff
## Employee: Joan | Position: Supervisor
## Employee: Alya | Position: Staff
## Employee: Dwi | Position: Manager
## Manager found! Loop stopped.
2.3 Break
break is used in programming to immediately stop a loop when a specific condition is met.
## nama: Bagas , salary: 5000
## nama: Joan , salary: 7000
## nama: Alya , salary: 6500
## nama: Dwi , salary: 10000
## (stopped because Nabil has a salary above 10000)
2.4 Continue
continue (called next in R) is used to skip the current iteration of a loop and move directly to the next iteration.
## name: bagas , performance: good
## name: joan , performance: very good
## name: dwi , performance: good
## name: nabil , performance: very good
## (alya) skipped because the performance is average