101.school
CoursesAbout
Search...⌘K
Generate a course with AI...

    Intro to computers and programming

    Receive aemail containing the next unit.
    • Computer Basics
      • 1.1Overview of Computers
      • 1.2Understanding Operating Systems
      • 1.3Understanding Computer Networks
    • Introduction to Programming
      • 2.1What is Programming?
      • 2.2Basics of a Program
      • 2.3How a Program Runs on a Computer
    • Introduction to Coding
      • 3.1Writing your First Code
      • 3.2Language of Coding
      • 3.3Common Coding Practices
    • Scripting Basics
      • 4.1What is Scripting?
      • 4.2Difference Between Coding and Scripting
      • 4.3First Look at Shell Scripts
    • Basics of a Programming Language
      • 5.1Understanding Syntax
      • 5.2Basic Constructs – Loops & Conditionals
      • 5.3Functions and Procedures
    • Intermediate Programming
      • 6.1Arrays and Lists
      • 6.2File Handling
      • 6.3Error Handling
    • Introduction to Object Oriented Programming
      • 7.1Principles of Object Oriented Programming
      • 7.2Classes and Objects
      • 7.3Inheritance and Encapsulation
    • Practical Uses of Scripting
      • 8.1Process Automation with Scripts
      • 8.2Using Scripts for Data Manipulation
      • 8.3Web Scraping with Scripts
    • Algorithms and Data Structures
      • 9.1Basics of Algorithms
      • 9.2Introduction to Data Structures
      • 9.3Practical Uses of Data Structures
    • Code Efficiency
      • 10.1Writing Efficient Code
      • 10.2Debugging and Testing
      • 10.3Code Performance Analysis
    • Managing Code Project
      • 11.1Understanding Version Control
      • 11.2Use of GitHub for Project Management
      • 11.3Collaborative Coding Practices
    • Real World Coding Examples
      • 12.1Review and Analysis of Real World Code
      • 12.2Case Study—Use of Code in Solving Real World Problems
      • 12.3Building and Presenting a Mini Coding Project
    • Future Learning and Wrap Up
      • 13.1Essentials for Advanced Learning
      • 13.2Overview of Other Programming Languages
      • 13.3Course Wrap Up and Next Steps

    Basics of a Programming Language

    Basic Constructs – Loops & Conditionals

    programming language construct that performs actions according to boolean conditions

    Programming language construct that performs actions according to boolean conditions.

    In the world of programming, control flow is a fundamental concept that allows your program to be dynamic and responsive. It is the order in which the program's code executes. The control flow of a program is regulated using conditional statements and loops, which together form the basic constructs of most programming languages.

    Understanding Conditional Statements

    Conditional statements are used to perform different actions based on different conditions. In simple terms, they allow your program to make decisions. The most common conditional statements are if, else, and switch.

    • If Statement: The if statement is used to specify a block of code to be executed if a specified condition is true.

    • Else Statement: The else statement is used to specify a block of code to be executed if the same condition is false.

    • Switch Statement: The switch statement is used to select one of many code blocks to be executed. It's a more efficient way to write a multi-way decision than using multiple if-else statements.

    Introduction to Loops

    Loops are used in programming to repeat a specific block of code until a certain condition is met. We use loops to automate repetitive tasks. The three most used types of loops are for, while, and do-while.

    • For Loop: The for loop is used when you know in advance how many times the script should run.

    • While Loop: The while loop is used when you want the script to loop as long as the condition is true.

    • Do-While Loop: The do-while loop is a variant of the while loop, which tests the condition at the end of the loop. This means that the loop will always be executed at least once, even if the condition is false.

    Practical Examples of Using Conditionals and Loops

    Let's look at a simple example in pseudo-code:

    // A simple if-else statement if (weather is sunny) go for a walk else read a book // A simple for loop for (i from 1 to 10) print i // A simple while loop while (there are items in the shopping list) buy item

    In conclusion, understanding loops and conditionals is crucial for controlling the flow of your programs. They allow your code to make decisions and repeat actions, making it more efficient and powerful.

    Test me
    Practical exercise
    Further reading

    Hey there, any questions I can help with?

    Sign in to chat
    Next up: Functions and Procedures