Assignment Week 4 ~ Syntax and Control Flow
Chelsea Tesalonika
Patricia Hutajulu
Bakti Siregar, M.Sc., CDS
Major : Data Science at ITSB
Data Science Programming
Introduction
Syntax and control flow are fundamental concepts in programming. Syntax refers to the rules that define how code should be written so it can be understood by a programming language, while control flow determines the order in which instructions are executed. By using control flow statements, programmers can make logical decisions, repeat tasks, and handle different conditions within a program. Understanding these concepts helps in creating code that is more structured, efficient, and easier to manage.
1. Dataset
2. Conditional Statements
Conditional statements are an important concept in programming that allow a program to make decisions based on specific conditions. By evaluating whether a condition is true or false, the program can execute different instructions. In this section, conditional statements are used to determine employee bonus levels based on their performance.
3. Loops (For & While)
3.1 For loop
Loops are used in programming to repeat a set of instructions multiple times. One common type is the for loop, which allows a program to iterate through a collection of data efficiently. In this section, a for loop is used to go through employee data and display the names of employees whose salaries are greater than 6000.
3.2 While loop
A while loop is used in programming to repeatedly execute a set of instructions as long as a specified condition remains true. This type of loop is useful when the number of iterations is not predetermined. In this section, a while loop is used to display employee data sequentially until a manager position is encountered.
3.3 Break
The break statement is used in programming to immediately terminate a loop when a specific condition is met. This allows the program to stop the iteration earlier without completing the entire loop. In this section, the break statement is applied to stop the loop when an employee with a salary above 10,000 is found.
3.4 Continue
The continue statement is used in programming to skip the current iteration of a loop and move directly to the next iteration. This allows certain conditions to be ignored without stopping the entire loop. In this section, the continue statement is used to skip employees whose performance is categorized as “Average”.
Conclusion
syntax and control flow help structure a program so it can perform tasks efficiently. By using conditional statements, the program can make decisions based on employee performance, such as calculating bonuses. Loops like for and while allow the program to process employee data repeatedly, while break and continue help control the execution of the loop. Overall, these concepts make the code more organized, flexible, and easier to manage when working with datasets.
Reference
[1] Siregar, B. (n.d.). Data Science Programming: Chapter 02: Syntax and Control Flow. dsciencelabs. https://bookdown.org/dsciencelabs/data_science_programming/02-Syntax-and-Control-Flow.html