Visual Basic loop structures allow you to run one or more lines of code repetitively. You can repeat the statements in a loop structure until a condition is True, until a condition is False, a specified number of times, or once for each element in a collection.
The while loop in C++ allows code to be repeatedly executed as long as a condition is true. The while statement checks the condition before executing the loop body, so the body may execute zero or more times. The loop condition must be initialized and updated within the body to ensure the algorithm eventually terminates. Statements in the body are executed until the condition becomes false, at which point program control continues after the loop.
The while loop in C++ allows code to be repeatedly executed as long as a condition is true. The while statement checks the condition before executing the loop body, so the body may execute zero or more times. The loop condition must be initialized and updated within the body to ensure the loop terminates. Statements in the body are executed until the condition becomes false, at which point program control continues after the loop.
Loops allow blocks of code to be repeatedly executed. The three types of loops in C are while loops, for loops, and do-while loops. While loops check the condition before each iteration. For loops allow initialization, condition checking, and increment/decrement in the loop header. Do-while loops check the condition after executing the block at least once. Break and continue statements can be used to exit or skip portions of loops. Switch statements compare a value to multiple case values and execute the corresponding block.
Loops in C++ allow programmers to repeatedly execute a block of code. There are three main types of loops in C++: while loops, do-while loops, and for loops. While loops and do-while loops check the loop condition at the end of each iteration and repeat the block while the condition is true. For loops allow initialization of a counter variable, a condition to test on each pass, and an update to the counter. For loops are useful when the number of iterations is known. Do-while loops differ in that the block is guaranteed to run at least once even if the condition is false.
Visual Basic loop structures allow you to run one or more lines of code repetitively. You can repeat the statements in a loop structure until a condition is True, until a condition is False, a specified number of times, or once for each element in a collection.
The while loop in C++ allows code to be repeatedly executed as long as a condition is true. The while statement checks the condition before executing the loop body, so the body may execute zero or more times. The loop condition must be initialized and updated within the body to ensure the algorithm eventually terminates. Statements in the body are executed until the condition becomes false, at which point program control continues after the loop.
The while loop in C++ allows code to be repeatedly executed as long as a condition is true. The while statement checks the condition before executing the loop body, so the body may execute zero or more times. The loop condition must be initialized and updated within the body to ensure the loop terminates. Statements in the body are executed until the condition becomes false, at which point program control continues after the loop.
Loops allow blocks of code to be repeatedly executed. The three types of loops in C are while loops, for loops, and do-while loops. While loops check the condition before each iteration. For loops allow initialization, condition checking, and increment/decrement in the loop header. Do-while loops check the condition after executing the block at least once. Break and continue statements can be used to exit or skip portions of loops. Switch statements compare a value to multiple case values and execute the corresponding block.
Loops in C++ allow programmers to repeatedly execute a block of code. There are three main types of loops in C++: while loops, do-while loops, and for loops. While loops and do-while loops check the loop condition at the end of each iteration and repeat the block while the condition is true. For loops allow initialization of a counter variable, a condition to test on each pass, and an update to the counter. For loops are useful when the number of iterations is known. Do-while loops differ in that the block is guaranteed to run at least once even if the condition is false.
Loops allow a set of instructions to be repeatedly executed until a certain condition is met. The document discusses the concept of loops and the for loop in particular. It defines loops, explains how they work by testing a condition and repeating a loop body, and lists the typical parts of a loop including initialization, test expression, and increment/decrement. It also describes different types of loops like for, while, and do-while loops. The structure and usage of the for loop is explained along with an example of a for loop printing numbers 1 through 10.
Loops allow code to be repeatedly executed. There are three common types of loops in C++: for, while, and do-while. For and while loops check the loop condition at the start (entry controlled), while do-while checks at the end (exit controlled), guaranteeing the body runs at least once. For loops use initialization, condition, and update expressions to control the loop. While loops test a condition to determine when to exit. Do-while also tests a condition, but runs the body first before checking. C++ is commonly used for programming due to its standard template library and suitability for tasks like gaming, development, and analytics.
C++ provides several types of loops to repeat blocks of code, including while, for, do-while, and nested loops. Loop control statements like break, continue, and goto change the normal execution flow. An infinite loop is one whose condition never becomes false, allowing the loop to repeat indefinitely until terminated.
Decision making:
In CSharp, various types of decision making statements are available such as if..else, if..else..if, switch etc. Each statement is used to evaluate the specific test. If tests are determined to be true, specific statement will be execued for example : if(a > b) statement1 else statement2. Sometimes when develpoing program that requires to take the decision to execute specific part of program, decision making statement helps to do so.
Switch Case
In CSharp switch acts like a multiple if / else if / else chain. Checks a value against a list of cases, and executes the first case that is true. If no matching case found, it executes the default case. The break(optional) statements with case indicate to the interpreter to end the particular case.
This document discusses loops in C++. It describes the parts of a loop including initialization, test, and update expressions. It explains the functioning of for, while, and do-while loops through examples. A for loop executes a sequence of statements multiple times in an abbreviated form. A while loop repeats statements as long as a condition is true, testing the condition first. A do-while loop evaluates the test expression after executing the loop body, so the body is executed at least once. Nested loops are used to repeat an inner loop multiple times for each iteration of an outer loop.
This document discusses loops in C++ programming. It defines while, for, and do-while loops and how each one works. It also describes loop control statements like break, continue, and goto that change the normal execution of loops. Finally, it provides an example of an infinite loop in C++ using a for loop without a conditional expression to repeat indefinitely.
This document discusses loops in C++. It defines for, while, and do-while loops and explains their syntax and functioning. For loops execute a sequence of statements multiple times using initialization, condition, and update expressions. While loops test the condition before executing the loop body, and do-while loops test after. Nested loops are used to repeat an inner loop multiple times for each iteration of the outer loop.
Session covers various flow control statements available in C#. Like if-else, switch-case, for, while, do-while, foreach, goto, break, continue, return, throw.
This document provides information about loop statements in programming. It discusses the different parts of a loop, types of loops including while, for, and do-while loops. It also covers nested loops and jump statements like break and continue. Examples are given for each loop type. The document concludes with multiple choice and program-based questions as exercises.
While, for, and do-while loops in C allow code to be repeatedly executed. The while loop repeats as long as a condition is true. The do-while loop executes the code block first and then checks the condition, repeating if it's true. The for loop allows initialization of a counter variable, a condition to test on each iteration, and an increment statement. All three loops repeat zero or more times until their condition becomes false.
While, for, and do-while loops in C allow code to be repeatedly executed. The while loop repeats as long as a condition is true. The do-while loop executes the statement block first and then checks the condition, repeating until it is false. The for loop allows initialization of a counter variable, a condition to test on each iteration, and an increment expression to modify the counter between iterations. All three loops repeat zero or more times until their condition becomes false.
The document discusses do-while loops and switch statements in C++. It provides explanations of the syntax and flow of do-while loops, including that the code block is executed at least once before the condition is checked. It also explains switch statements, including that they provide an alternative to nested if-else statements when there are multiple choices and only one should be executed. Examples are provided of using do-while loops to display numbers and switch statements to perform arithmetic operations based on an operator.
Control statements regulate the order of execution of statements in a program. There are three main types of control statements: sequence statements, selection statements (if/else, switch), and looping/iteration statements (for, while, do-while). Sequence statements execute statements sequentially from top to bottom. Selection statements execute certain statements conditionally based on if/else or switch conditions. Looping statements repeatedly execute a block of code for a specified number of times or as long as a condition is true. Other statements like break, continue, and return can change the normal flow of control.
The document discusses different types of loops in computer programming including for, while, do-while, and infinite loops. It provides examples of using each loop type to print "Hello World" multiple times and explains the key differences between while and do-while loops. While loops check the loop condition first before executing the body, whereas do-while loops always execute the body at least once before checking the condition. Infinite loops occur when the loop condition is never false, causing the loop to repeat indefinitely until terminated.
This document discusses different types of loop constructs in C programming language. It describes while, do-while and for loops. While and do-while loops execute statements repeatedly as long as a given condition is true. For loops allow initialization of counters, check a condition, and update the counter each iteration. The document also covers flow charts to illustrate loop execution and examples of each loop type as well as continue, break and goto statements that change loop flow.
This document discusses different types of loops in Java programming: while, for, do-while, and enhanced for loops. It provides the syntax and flow for each loop type along with examples. The key loop types are:
- While loops repeat while a condition is true, testing at the start of each iteration.
- For loops iterate a specific number of times, with initialization, condition, and update sections.
- Do-while loops are like while loops but test the condition at the end, so the body executes at least once.
- Enhanced for loops iterate over collections/arrays, declaring a block variable to access each element.
This document discusses different types of loops and conditional statements in programming. It describes for, while, do-while, and foreach loops. For loops repeat a block of code a specified number of times. While loops repeat as long as a condition is true. Do-while loops execute code once then repeat as long as the condition is true. Foreach loops iterate over elements in an array. The document also covers if, else if, else, and switch conditional statements. If statements execute code if a condition is true, and else executes it if false. Switch compares a value to multiple cases.
Null Bangalore | Pentesters Approach to AWS IAMDivyanshu
#Abstract:
- Learn more about the real-world methods for auditing AWS IAM (Identity and Access Management) as a pentester. So let us proceed with a brief discussion of IAM as well as some typical misconfigurations and their potential exploits in order to reinforce the understanding of IAM security best practices.
- Gain actionable insights into AWS IAM policies and roles, using hands on approach.
#Prerequisites:
- Basic understanding of AWS services and architecture
- Familiarity with cloud security concepts
- Experience using the AWS Management Console or AWS CLI.
- For hands on lab create account on [killercoda.com](https://killercoda.com/cloudsecurity-scenario/)
# Scenario Covered:
- Basics of IAM in AWS
- Implementing IAM Policies with Least Privilege to Manage S3 Bucket
- Objective: Create an S3 bucket with least privilege IAM policy and validate access.
- Steps:
- Create S3 bucket.
- Attach least privilege policy to IAM user.
- Validate access.
- Exploiting IAM PassRole Misconfiguration
-Allows a user to pass a specific IAM role to an AWS service (ec2), typically used for service access delegation. Then exploit PassRole Misconfiguration granting unauthorized access to sensitive resources.
- Objective: Demonstrate how a PassRole misconfiguration can grant unauthorized access.
- Steps:
- Allow user to pass IAM role to EC2.
- Exploit misconfiguration for unauthorized access.
- Access sensitive resources.
- Exploiting IAM AssumeRole Misconfiguration with Overly Permissive Role
- An overly permissive IAM role configuration can lead to privilege escalation by creating a role with administrative privileges and allow a user to assume this role.
- Objective: Show how overly permissive IAM roles can lead to privilege escalation.
- Steps:
- Create role with administrative privileges.
- Allow user to assume the role.
- Perform administrative actions.
- Differentiation between PassRole vs AssumeRole
Try at [killercoda.com](https://killercoda.com/cloudsecurity-scenario/)
Loops allow a set of instructions to be repeatedly executed until a certain condition is met. The document discusses the concept of loops and the for loop in particular. It defines loops, explains how they work by testing a condition and repeating a loop body, and lists the typical parts of a loop including initialization, test expression, and increment/decrement. It also describes different types of loops like for, while, and do-while loops. The structure and usage of the for loop is explained along with an example of a for loop printing numbers 1 through 10.
Loops allow code to be repeatedly executed. There are three common types of loops in C++: for, while, and do-while. For and while loops check the loop condition at the start (entry controlled), while do-while checks at the end (exit controlled), guaranteeing the body runs at least once. For loops use initialization, condition, and update expressions to control the loop. While loops test a condition to determine when to exit. Do-while also tests a condition, but runs the body first before checking. C++ is commonly used for programming due to its standard template library and suitability for tasks like gaming, development, and analytics.
C++ provides several types of loops to repeat blocks of code, including while, for, do-while, and nested loops. Loop control statements like break, continue, and goto change the normal execution flow. An infinite loop is one whose condition never becomes false, allowing the loop to repeat indefinitely until terminated.
Decision making:
In CSharp, various types of decision making statements are available such as if..else, if..else..if, switch etc. Each statement is used to evaluate the specific test. If tests are determined to be true, specific statement will be execued for example : if(a > b) statement1 else statement2. Sometimes when develpoing program that requires to take the decision to execute specific part of program, decision making statement helps to do so.
Switch Case
In CSharp switch acts like a multiple if / else if / else chain. Checks a value against a list of cases, and executes the first case that is true. If no matching case found, it executes the default case. The break(optional) statements with case indicate to the interpreter to end the particular case.
This document discusses loops in C++. It describes the parts of a loop including initialization, test, and update expressions. It explains the functioning of for, while, and do-while loops through examples. A for loop executes a sequence of statements multiple times in an abbreviated form. A while loop repeats statements as long as a condition is true, testing the condition first. A do-while loop evaluates the test expression after executing the loop body, so the body is executed at least once. Nested loops are used to repeat an inner loop multiple times for each iteration of an outer loop.
This document discusses loops in C++ programming. It defines while, for, and do-while loops and how each one works. It also describes loop control statements like break, continue, and goto that change the normal execution of loops. Finally, it provides an example of an infinite loop in C++ using a for loop without a conditional expression to repeat indefinitely.
This document discusses loops in C++. It defines for, while, and do-while loops and explains their syntax and functioning. For loops execute a sequence of statements multiple times using initialization, condition, and update expressions. While loops test the condition before executing the loop body, and do-while loops test after. Nested loops are used to repeat an inner loop multiple times for each iteration of the outer loop.
Session covers various flow control statements available in C#. Like if-else, switch-case, for, while, do-while, foreach, goto, break, continue, return, throw.
This document provides information about loop statements in programming. It discusses the different parts of a loop, types of loops including while, for, and do-while loops. It also covers nested loops and jump statements like break and continue. Examples are given for each loop type. The document concludes with multiple choice and program-based questions as exercises.
While, for, and do-while loops in C allow code to be repeatedly executed. The while loop repeats as long as a condition is true. The do-while loop executes the code block first and then checks the condition, repeating if it's true. The for loop allows initialization of a counter variable, a condition to test on each iteration, and an increment statement. All three loops repeat zero or more times until their condition becomes false.
While, for, and do-while loops in C allow code to be repeatedly executed. The while loop repeats as long as a condition is true. The do-while loop executes the statement block first and then checks the condition, repeating until it is false. The for loop allows initialization of a counter variable, a condition to test on each iteration, and an increment expression to modify the counter between iterations. All three loops repeat zero or more times until their condition becomes false.
The document discusses do-while loops and switch statements in C++. It provides explanations of the syntax and flow of do-while loops, including that the code block is executed at least once before the condition is checked. It also explains switch statements, including that they provide an alternative to nested if-else statements when there are multiple choices and only one should be executed. Examples are provided of using do-while loops to display numbers and switch statements to perform arithmetic operations based on an operator.
Control statements regulate the order of execution of statements in a program. There are three main types of control statements: sequence statements, selection statements (if/else, switch), and looping/iteration statements (for, while, do-while). Sequence statements execute statements sequentially from top to bottom. Selection statements execute certain statements conditionally based on if/else or switch conditions. Looping statements repeatedly execute a block of code for a specified number of times or as long as a condition is true. Other statements like break, continue, and return can change the normal flow of control.
The document discusses different types of loops in computer programming including for, while, do-while, and infinite loops. It provides examples of using each loop type to print "Hello World" multiple times and explains the key differences between while and do-while loops. While loops check the loop condition first before executing the body, whereas do-while loops always execute the body at least once before checking the condition. Infinite loops occur when the loop condition is never false, causing the loop to repeat indefinitely until terminated.
This document discusses different types of loop constructs in C programming language. It describes while, do-while and for loops. While and do-while loops execute statements repeatedly as long as a given condition is true. For loops allow initialization of counters, check a condition, and update the counter each iteration. The document also covers flow charts to illustrate loop execution and examples of each loop type as well as continue, break and goto statements that change loop flow.
This document discusses different types of loops in Java programming: while, for, do-while, and enhanced for loops. It provides the syntax and flow for each loop type along with examples. The key loop types are:
- While loops repeat while a condition is true, testing at the start of each iteration.
- For loops iterate a specific number of times, with initialization, condition, and update sections.
- Do-while loops are like while loops but test the condition at the end, so the body executes at least once.
- Enhanced for loops iterate over collections/arrays, declaring a block variable to access each element.
This document discusses different types of loops and conditional statements in programming. It describes for, while, do-while, and foreach loops. For loops repeat a block of code a specified number of times. While loops repeat as long as a condition is true. Do-while loops execute code once then repeat as long as the condition is true. Foreach loops iterate over elements in an array. The document also covers if, else if, else, and switch conditional statements. If statements execute code if a condition is true, and else executes it if false. Switch compares a value to multiple cases.
Similaire à While Loop in python engineering .pdf (20)
Null Bangalore | Pentesters Approach to AWS IAMDivyanshu
#Abstract:
- Learn more about the real-world methods for auditing AWS IAM (Identity and Access Management) as a pentester. So let us proceed with a brief discussion of IAM as well as some typical misconfigurations and their potential exploits in order to reinforce the understanding of IAM security best practices.
- Gain actionable insights into AWS IAM policies and roles, using hands on approach.
#Prerequisites:
- Basic understanding of AWS services and architecture
- Familiarity with cloud security concepts
- Experience using the AWS Management Console or AWS CLI.
- For hands on lab create account on [killercoda.com](https://killercoda.com/cloudsecurity-scenario/)
# Scenario Covered:
- Basics of IAM in AWS
- Implementing IAM Policies with Least Privilege to Manage S3 Bucket
- Objective: Create an S3 bucket with least privilege IAM policy and validate access.
- Steps:
- Create S3 bucket.
- Attach least privilege policy to IAM user.
- Validate access.
- Exploiting IAM PassRole Misconfiguration
-Allows a user to pass a specific IAM role to an AWS service (ec2), typically used for service access delegation. Then exploit PassRole Misconfiguration granting unauthorized access to sensitive resources.
- Objective: Demonstrate how a PassRole misconfiguration can grant unauthorized access.
- Steps:
- Allow user to pass IAM role to EC2.
- Exploit misconfiguration for unauthorized access.
- Access sensitive resources.
- Exploiting IAM AssumeRole Misconfiguration with Overly Permissive Role
- An overly permissive IAM role configuration can lead to privilege escalation by creating a role with administrative privileges and allow a user to assume this role.
- Objective: Show how overly permissive IAM roles can lead to privilege escalation.
- Steps:
- Create role with administrative privileges.
- Allow user to assume the role.
- Perform administrative actions.
- Differentiation between PassRole vs AssumeRole
Try at [killercoda.com](https://killercoda.com/cloudsecurity-scenario/)
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELijaia
As digital technology becomes more deeply embedded in power systems, protecting the communication
networks of Smart Grids (SG) has emerged as a critical concern. Distributed Network Protocol 3 (DNP3)
represents a multi-tiered application layer protocol extensively utilized in Supervisory Control and Data
Acquisition (SCADA)-based smart grids to facilitate real-time data gathering and control functionalities.
Robust Intrusion Detection Systems (IDS) are necessary for early threat detection and mitigation because
of the interconnection of these networks, which makes them vulnerable to a variety of cyberattacks. To
solve this issue, this paper develops a hybrid Deep Learning (DL) model specifically designed for intrusion
detection in smart grids. The proposed approach is a combination of the Convolutional Neural Network
(CNN) and the Long-Short-Term Memory algorithms (LSTM). We employed a recent intrusion detection
dataset (DNP3), which focuses on unauthorized commands and Denial of Service (DoS) cyberattacks, to
train and test our model. The results of our experiments show that our CNN-LSTM method is much better
at finding smart grid intrusions than other deep learning algorithms used for classification. In addition,
our proposed approach improves accuracy, precision, recall, and F1 score, achieving a high detection
accuracy rate of 99.50%.
Digital Twins Computer Networking Paper Presentation.pptxaryanpankaj78
A Digital Twin in computer networking is a virtual representation of a physical network, used to simulate, analyze, and optimize network performance and reliability. It leverages real-time data to enhance network management, predict issues, and improve decision-making processes.
Supermarket Management System Project Report.pdfKamal Acharya
Supermarket management is a stand-alone J2EE using Eclipse Juno program.
This project contains all the necessary required information about maintaining
the supermarket billing system.
The core idea of this project to minimize the paper work and centralize the
data. Here all the communication is taken in secure manner. That is, in this
application the information will be stored in client itself. For further security the
data base is stored in the back-end oracle and so no intruders can access it.
Generative AI Use cases applications solutions and implementation.pdfmahaffeycheryld
Generative AI solutions encompass a range of capabilities from content creation to complex problem-solving across industries. Implementing generative AI involves identifying specific business needs, developing tailored AI models using techniques like GANs and VAEs, and integrating these models into existing workflows. Data quality and continuous model refinement are crucial for effective implementation. Businesses must also consider ethical implications and ensure transparency in AI decision-making. Generative AI's implementation aims to enhance efficiency, creativity, and innovation by leveraging autonomous generation and sophisticated learning algorithms to meet diverse business challenges.
https://www.leewayhertz.com/generative-ai-use-cases-and-applications/
Applications of artificial Intelligence in Mechanical Engineering.pdfAtif Razi
Historically, mechanical engineering has relied heavily on human expertise and empirical methods to solve complex problems. With the introduction of computer-aided design (CAD) and finite element analysis (FEA), the field took its first steps towards digitization. These tools allowed engineers to simulate and analyze mechanical systems with greater accuracy and efficiency. However, the sheer volume of data generated by modern engineering systems and the increasing complexity of these systems have necessitated more advanced analytical tools, paving the way for AI.
AI offers the capability to process vast amounts of data, identify patterns, and make predictions with a level of speed and accuracy unattainable by traditional methods. This has profound implications for mechanical engineering, enabling more efficient design processes, predictive maintenance strategies, and optimized manufacturing operations. AI-driven tools can learn from historical data, adapt to new information, and continuously improve their performance, making them invaluable in tackling the multifaceted challenges of modern mechanical engineering.
Discover the latest insights on Data Driven Maintenance with our comprehensive webinar presentation. Learn about traditional maintenance challenges, the right approach to utilizing data, and the benefits of adopting a Data Driven Maintenance strategy. Explore real-world examples, industry best practices, and innovative solutions like FMECA and the D3M model. This presentation, led by expert Jules Oudmans, is essential for asset owners looking to optimize their maintenance processes and leverage digital technologies for improved efficiency and performance. Download now to stay ahead in the evolving maintenance landscape.
Software Engineering and Project Management - Software Testing + Agile Method...Prakhyath Rai
Software Testing: A Strategic Approach to Software Testing, Strategic Issues, Test Strategies for Conventional Software, Test Strategies for Object -Oriented Software, Validation Testing, System Testing, The Art of Debugging.
Agile Methodology: Before Agile – Waterfall, Agile Development.
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...PriyankaKilaniya
Energy efficiency has been important since the latter part of the last century. The main object of this survey is to determine the energy efficiency knowledge among consumers. Two separate districts in Bangladesh are selected to conduct the survey on households and showrooms about the energy and seller also. The survey uses the data to find some regression equations from which it is easy to predict energy efficiency knowledge. The data is analyzed and calculated based on five important criteria. The initial target was to find some factors that help predict a person's energy efficiency knowledge. From the survey, it is found that the energy efficiency awareness among the people of our country is very low. Relationships between household energy use behaviors are estimated using a unique dataset of about 40 households and 20 showrooms in Bangladesh's Chapainawabganj and Bagerhat districts. Knowledge of energy consumption and energy efficiency technology options is found to be associated with household use of energy conservation practices. Household characteristics also influence household energy use behavior. Younger household cohorts are more likely to adopt energy-efficient technologies and energy conservation practices and place primary importance on energy saving for environmental reasons. Education also influences attitudes toward energy conservation in Bangladesh. Low-education households indicate they primarily save electricity for the environment while high-education households indicate they are motivated by environmental concerns.
Software Engineering and Project Management - Introduction, Modeling Concepts...Prakhyath Rai
Introduction, Modeling Concepts and Class Modeling: What is Object orientation? What is OO development? OO Themes; Evidence for usefulness of OO development; OO modeling history. Modeling
as Design technique: Modeling, abstraction, The Three models. Class Modeling: Object and Class Concept, Link and associations concepts, Generalization and Inheritance, A sample class model, Navigation of class models, and UML diagrams
Building the Analysis Models: Requirement Analysis, Analysis Model Approaches, Data modeling Concepts, Object Oriented Analysis, Scenario-Based Modeling, Flow-Oriented Modeling, class Based Modeling, Creating a Behavioral Model.
3. Python supports to have an else statement associated with a loop
statement
If else statement is used with a while loop, the else statement is
executed when the condition becomes false
Using else statement with a while loop
while condition:
# Code to be executed when the condition is True
else:
# Code to be executed when the condition becomes False
Syntax
4. Introduction to while loop
A while loop allows general repetition based upon the repeated
testing of a Boolean condition
Where, loop body contain the single statement or set of statements
(compound statement) or an empty statement.
A while loop is used to execute a set of statements as long as
condition is true
A loop statement allows us to execute a statement multiple times
5. Syntax How the While Loop
Works
1 Initialization
Set the initial state of the loop
variables.
2 Condition Check
Evaluate the condition expression to
determine if the loop should
continue.
3 Code Execution
Execute the code block within the
loop.
while(condition):
#code
#Initialization
7. 05
Examples
i = 0 # Initialize a variable
while i < 5: # While the variable is
print(i) less than 5
i+=1 print the variable and
increment it by 1
# The loop will stop when i is equal to 5
# Initialize a list
nums = [1, 2, 3, 4, 5]
# Iterate over the list and print each element
i = 0
while i < len(nums):
print(nums[i])
i += 1
# The loop will stop when i is equal to the length of the list