SlideShare a Scribd company logo
C# LOOPS STATEMENTS
There may be a situation, when you need to execute a block of code several number
of times. In general, the statements are executed sequentially: The first statement in a
function is executed first, followed by the second, and so on.
A loop statement allows us to execute a statement or a group of statements multiple
times
do
{
statement;
}
while(condition)
For(start;stop;step)
{
statement;
}
while(condition)
{
statement;
}
For(Initial Value; Condition; Steps)
{
statements;
}
The For loop statement is used in C# to execute a code
multiple times
FOR LOOP
private void button1_Click(object sender, EventArgs e)
{
for(int i=0;i<=4;i++)
{
MessageBox.Show("hello");
}
}
EXAMPLE 1
User for loop to show hello 5 times in a messagebox
private void button1_Click(object sender, EventArgs e)
{
for(int i=1;i<=10;i++)
{
MessageBox.Show(i.ToString());
}
}
Use for loop to show from 1 to 10 in a messagebox
EXAMPLE 2
private void button1_Click(object sender, EventArgs e)
{
for(int i=1;i<=100;i++)
{
listBox1.Items.Add(i.ToString());
}
}
EXAMPLE 3
Use for loop to insert numbers from 1 to 100 to a list box
private void button1_Click(object sender, EventArgs e)
{
for(char i='A';i<='Z';i++)
{
listBox1.Items.Add(i);
}
}
EXAMPLE 4
Use for loop to insert upper case alphabet to a list box
private void button1_Click(object sender, EventArgs e)
{
for(int i=100;i>=0;i--)
{
listBox1.Items.Add(i.ToString());
}
}
EXAMPLE 5
Use for loop to insert numbers from 100 to 1 to a list box
private void button1_Click(object sender, EventArgs e)
{
for (int i=1;i<=100;i++)
{
if(i%2==0)
{
listBox1.Items.Add(i.ToString());
}
}
}
EXAMPLE 6
Use for loop to insert even numbers from 1 to 100 to a list
box
private void button1_Click(object sender, EventArgs e)
{
for (int i=0;i<=100;i++)
{
if(i%5==0)
{
listBox1.Items.Add(i.ToString());
}
}
}
EXAMPLE 7
Using for loop insert {0,5,10,15,20,15,30,35,…..100}to
listbox
private void button1_Click(object sender, EventArgs e)
{
for (int i=0;i<=100;i++)
{
listBox1.Items.Add(i.ToString());
}
}
while(condition)
{
statement(s);
}
The while statement continually executes a block of statements until
a specified expression evaluates to false . The expression is
evaluated each time the loop is encountered and the evaluation result
is true, the loop body statements are executed.
WHILE LOOP
private void button1_Click(object sender, EventArgs e)
{
int i = 0;
while(i<=4)
{
MessageBox.Show("hello");
i++;
}
}
EXAMPLE 8
Use while loop to show hello 5 times
private void button1_Click(object sender, EventArgs e)
{
int i = 1;
while(i<=10)
{
if (i % 2 == 0)
{
listBox1.Items.Add(i.ToString());
}
i++;
}
}
EXAMPLE 9
Use while loop to add even number 1:10 to list box
Do
{
statement(s);
}
while(condition)
The Do while statement continually executes a block of statements
until a specified expression evaluates to false . The expression is
evaluated each time the loop is encountered and the evaluation result
is true, the loop body statements are executed.
DO WHILE LOOP
private void button1_Click(object sender, EventArgs e)
{
int i = 0;
do
{
MessageBox.Show("hello");
i++;
}
while (i <= 4);
}
EXAMPLE 10
User Do whileto show hello 5 times in a messagebox

More Related Content

What's hot

次世代PHPフレームワーク Symfony2
次世代PHPフレームワーク Symfony2次世代PHPフレームワーク Symfony2
次世代PHPフレームワーク Symfony2
Masao Maeda
 
week-18x
week-18xweek-18x
C++ control loops
C++ control loopsC++ control loops
C++ control loops
pratikborsadiya
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
Syed Umair
 
ICP - Lecture 9
ICP - Lecture 9ICP - Lecture 9
ICP - Lecture 9
hassaanciit
 
week-4x
week-4xweek-4x
5 Rmi Print
5  Rmi Print5  Rmi Print
5 Rmi Print
varadasuren
 
csc 208
csc 208csc 208
csc 208
priska
 
Matlab code for secant method
Matlab code for secant methodMatlab code for secant method
Matlab code for secant method
Taimoor Muzaffar Gondal
 
Python programs - PPT file (Polytechnics)
Python programs - PPT file (Polytechnics)Python programs - PPT file (Polytechnics)
Python programs - PPT file (Polytechnics)
SHAMJITH KM
 
Torchbearersnotebook.blogspot.com program to create a list in python and valu...
Torchbearersnotebook.blogspot.com program to create a list in python and valu...Torchbearersnotebook.blogspot.com program to create a list in python and valu...
Torchbearersnotebook.blogspot.com program to create a list in python and valu...
SAKSHISINGH486
 
escape sequences and substitution markers
escape sequences and substitution markersescape sequences and substitution markers
escape sequences and substitution markers
Micheal Ogundero
 
10. NULL pointer
10. NULL pointer10. NULL pointer
10. NULL pointer
Gem WeBlog
 
Debugger Of Turbo C
Debugger Of Turbo CDebugger Of Turbo C
Debugger Of Turbo C
mohit2501
 
Cinfo
CinfoCinfo
Cinfo
teach4uin
 
CalculateLoanPayments
CalculateLoanPaymentsCalculateLoanPayments
CalculateLoanPayments
William Rutherford
 
Ruby mine referencecard
Ruby mine referencecardRuby mine referencecard
Ruby mine referencecard
sushilprajapati
 
StackArray stack3
StackArray stack3StackArray stack3
StackArray stack3
Rajendran
 
Switch statement mcq
Switch statement  mcqSwitch statement  mcq
Switch statement mcq
Parthipan Parthi
 
Ejercicios En Gambas
Ejercicios En GambasEjercicios En Gambas
Ejercicios En Gambas
mafermen7
 

What's hot (20)

次世代PHPフレームワーク Symfony2
次世代PHPフレームワーク Symfony2次世代PHPフレームワーク Symfony2
次世代PHPフレームワーク Symfony2
 
week-18x
week-18xweek-18x
week-18x
 
C++ control loops
C++ control loopsC++ control loops
C++ control loops
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
ICP - Lecture 9
ICP - Lecture 9ICP - Lecture 9
ICP - Lecture 9
 
week-4x
week-4xweek-4x
week-4x
 
5 Rmi Print
5  Rmi Print5  Rmi Print
5 Rmi Print
 
csc 208
csc 208csc 208
csc 208
 
Matlab code for secant method
Matlab code for secant methodMatlab code for secant method
Matlab code for secant method
 
Python programs - PPT file (Polytechnics)
Python programs - PPT file (Polytechnics)Python programs - PPT file (Polytechnics)
Python programs - PPT file (Polytechnics)
 
Torchbearersnotebook.blogspot.com program to create a list in python and valu...
Torchbearersnotebook.blogspot.com program to create a list in python and valu...Torchbearersnotebook.blogspot.com program to create a list in python and valu...
Torchbearersnotebook.blogspot.com program to create a list in python and valu...
 
escape sequences and substitution markers
escape sequences and substitution markersescape sequences and substitution markers
escape sequences and substitution markers
 
10. NULL pointer
10. NULL pointer10. NULL pointer
10. NULL pointer
 
Debugger Of Turbo C
Debugger Of Turbo CDebugger Of Turbo C
Debugger Of Turbo C
 
Cinfo
CinfoCinfo
Cinfo
 
CalculateLoanPayments
CalculateLoanPaymentsCalculateLoanPayments
CalculateLoanPayments
 
Ruby mine referencecard
Ruby mine referencecardRuby mine referencecard
Ruby mine referencecard
 
StackArray stack3
StackArray stack3StackArray stack3
StackArray stack3
 
Switch statement mcq
Switch statement  mcqSwitch statement  mcq
Switch statement mcq
 
Ejercicios En Gambas
Ejercicios En GambasEjercicios En Gambas
Ejercicios En Gambas
 

Similar to Vs c# lecture7 2

Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
PRN USM
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6
Vince Vo
 
Property Based Testing
Property Based TestingProperty Based Testing
Property Based Testing
Shishir Dwivedi
 
130707833146508191
130707833146508191130707833146508191
130707833146508191
Tanzeel Ahmad
 
C++ loop
C++ loop C++ loop
C++ loop
Khelan Ameen
 
Loop structures chpt_6
Loop structures chpt_6Loop structures chpt_6
Loop structures chpt_6
cmontanez
 
Module 5 : Statements & Exceptions
Module 5 : Statements & ExceptionsModule 5 : Statements & Exceptions
Module 5 : Statements & Exceptions
Prem Kumar Badri
 
C# Loops
C# LoopsC# Loops
C# Loops
guestae0484
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
jahanullah
 
3. control statement
3. control statement3. control statement
3. control statement
Shankar Gangaju
 
C#
C#C#
C++ control structure
C++ control structureC++ control structure
C++ control structure
bluejayjunior
 
07 flow control
07   flow control07   flow control
07 flow control
dhrubo kayal
 
Loops
LoopsLoops
Loops
Kamran
 
Java presentation
Java presentationJava presentation
Java presentation
Muhammad Saleem Nagri
 
SPL 8 | Loop Statements in C
SPL 8 | Loop Statements in CSPL 8 | Loop Statements in C
SPL 8 | Loop Statements in C
Mohammad Imam Hossain
 
130706266060138191
130706266060138191130706266060138191
130706266060138191
Tanzeel Ahmad
 
Loops c++
Loops c++Loops c++
Loops c++
Shivani Singh
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
Suhail Akraam
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in java
yugandhar vadlamudi
 

Similar to Vs c# lecture7 2 (20)

Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6
 
Property Based Testing
Property Based TestingProperty Based Testing
Property Based Testing
 
130707833146508191
130707833146508191130707833146508191
130707833146508191
 
C++ loop
C++ loop C++ loop
C++ loop
 
Loop structures chpt_6
Loop structures chpt_6Loop structures chpt_6
Loop structures chpt_6
 
Module 5 : Statements & Exceptions
Module 5 : Statements & ExceptionsModule 5 : Statements & Exceptions
Module 5 : Statements & Exceptions
 
C# Loops
C# LoopsC# Loops
C# Loops
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
 
3. control statement
3. control statement3. control statement
3. control statement
 
C#
C#C#
C#
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
 
07 flow control
07   flow control07   flow control
07 flow control
 
Loops
LoopsLoops
Loops
 
Java presentation
Java presentationJava presentation
Java presentation
 
SPL 8 | Loop Statements in C
SPL 8 | Loop Statements in CSPL 8 | Loop Statements in C
SPL 8 | Loop Statements in C
 
130706266060138191
130706266060138191130706266060138191
130706266060138191
 
Loops c++
Loops c++Loops c++
Loops c++
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
Control flow statements in java
Control flow statements in javaControl flow statements in java
Control flow statements in java
 

More from Saman M. Almufti

Lecture 7- domain name
Lecture  7- domain nameLecture  7- domain name
Lecture 7- domain name
Saman M. Almufti
 
Vp lecture 11 ararat
Vp lecture 11 araratVp lecture 11 ararat
Vp lecture 11 ararat
Saman M. Almufti
 
Vp lecture 10 ararat
Vp lecture 10 araratVp lecture 10 ararat
Vp lecture 10 ararat
Saman M. Almufti
 
Vp lecture 12 ararat
Vp lecture 12 araratVp lecture 12 ararat
Vp lecture 12 ararat
Saman M. Almufti
 
Lecture 6- http
Lecture  6- httpLecture  6- http
Lecture 6- http
Saman M. Almufti
 
Lecture 5- url-dns
Lecture  5- url-dnsLecture  5- url-dns
Lecture 5- url-dns
Saman M. Almufti
 
Vp lecture 7 ararat
Vp lecture 7 araratVp lecture 7 ararat
Vp lecture 7 ararat
Saman M. Almufti
 
Lecture 4- ip
Lecture  4- ipLecture  4- ip
Lecture 4- ip
Saman M. Almufti
 
Vp lecture 6 ararat
Vp lecture 6 araratVp lecture 6 ararat
Vp lecture 6 ararat
Saman M. Almufti
 
Vp lecture 5 ararat
Vp lecture 5 araratVp lecture 5 ararat
Vp lecture 5 ararat
Saman M. Almufti
 
Lecture 3- tcp-ip
Lecture  3- tcp-ipLecture  3- tcp-ip
Lecture 3- tcp-ip
Saman M. Almufti
 
Vp lecture 4 ararat
Vp lecture 4 araratVp lecture 4 ararat
Vp lecture 4 ararat
Saman M. Almufti
 
Vp lecture 3 ararat
Vp lecture 3 araratVp lecture 3 ararat
Vp lecture 3 ararat
Saman M. Almufti
 
Lecture 2- terminology
Lecture  2- terminologyLecture  2- terminology
Lecture 2- terminology
Saman M. Almufti
 
Vp lecture 2 ararat
Vp lecture 2 araratVp lecture 2 ararat
Vp lecture 2 ararat
Saman M. Almufti
 
Vp lecture1 ararat
Vp lecture1 araratVp lecture1 ararat
Vp lecture1 ararat
Saman M. Almufti
 
Lecture 1- introduction
Lecture  1- introductionLecture  1- introduction
Lecture 1- introduction
Saman M. Almufti
 
Vs c# lecture12
Vs c# lecture12Vs c# lecture12
Vs c# lecture12
Saman M. Almufti
 
Vs c# lecture11
Vs c# lecture11Vs c# lecture11
Vs c# lecture11
Saman M. Almufti
 
Vs c# lecture10
Vs c# lecture10Vs c# lecture10
Vs c# lecture10
Saman M. Almufti
 

More from Saman M. Almufti (20)

Lecture 7- domain name
Lecture  7- domain nameLecture  7- domain name
Lecture 7- domain name
 
Vp lecture 11 ararat
Vp lecture 11 araratVp lecture 11 ararat
Vp lecture 11 ararat
 
Vp lecture 10 ararat
Vp lecture 10 araratVp lecture 10 ararat
Vp lecture 10 ararat
 
Vp lecture 12 ararat
Vp lecture 12 araratVp lecture 12 ararat
Vp lecture 12 ararat
 
Lecture 6- http
Lecture  6- httpLecture  6- http
Lecture 6- http
 
Lecture 5- url-dns
Lecture  5- url-dnsLecture  5- url-dns
Lecture 5- url-dns
 
Vp lecture 7 ararat
Vp lecture 7 araratVp lecture 7 ararat
Vp lecture 7 ararat
 
Lecture 4- ip
Lecture  4- ipLecture  4- ip
Lecture 4- ip
 
Vp lecture 6 ararat
Vp lecture 6 araratVp lecture 6 ararat
Vp lecture 6 ararat
 
Vp lecture 5 ararat
Vp lecture 5 araratVp lecture 5 ararat
Vp lecture 5 ararat
 
Lecture 3- tcp-ip
Lecture  3- tcp-ipLecture  3- tcp-ip
Lecture 3- tcp-ip
 
Vp lecture 4 ararat
Vp lecture 4 araratVp lecture 4 ararat
Vp lecture 4 ararat
 
Vp lecture 3 ararat
Vp lecture 3 araratVp lecture 3 ararat
Vp lecture 3 ararat
 
Lecture 2- terminology
Lecture  2- terminologyLecture  2- terminology
Lecture 2- terminology
 
Vp lecture 2 ararat
Vp lecture 2 araratVp lecture 2 ararat
Vp lecture 2 ararat
 
Vp lecture1 ararat
Vp lecture1 araratVp lecture1 ararat
Vp lecture1 ararat
 
Lecture 1- introduction
Lecture  1- introductionLecture  1- introduction
Lecture 1- introduction
 
Vs c# lecture12
Vs c# lecture12Vs c# lecture12
Vs c# lecture12
 
Vs c# lecture11
Vs c# lecture11Vs c# lecture11
Vs c# lecture11
 
Vs c# lecture10
Vs c# lecture10Vs c# lecture10
Vs c# lecture10
 

Recently uploaded

みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 

Recently uploaded (20)

みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 

Vs c# lecture7 2

  • 1.
  • 2.
  • 3. C# LOOPS STATEMENTS There may be a situation, when you need to execute a block of code several number of times. In general, the statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on. A loop statement allows us to execute a statement or a group of statements multiple times do { statement; } while(condition) For(start;stop;step) { statement; } while(condition) { statement; }
  • 4. For(Initial Value; Condition; Steps) { statements; } The For loop statement is used in C# to execute a code multiple times FOR LOOP
  • 5. private void button1_Click(object sender, EventArgs e) { for(int i=0;i<=4;i++) { MessageBox.Show("hello"); } } EXAMPLE 1 User for loop to show hello 5 times in a messagebox
  • 6. private void button1_Click(object sender, EventArgs e) { for(int i=1;i<=10;i++) { MessageBox.Show(i.ToString()); } } Use for loop to show from 1 to 10 in a messagebox EXAMPLE 2
  • 7. private void button1_Click(object sender, EventArgs e) { for(int i=1;i<=100;i++) { listBox1.Items.Add(i.ToString()); } } EXAMPLE 3 Use for loop to insert numbers from 1 to 100 to a list box
  • 8. private void button1_Click(object sender, EventArgs e) { for(char i='A';i<='Z';i++) { listBox1.Items.Add(i); } } EXAMPLE 4 Use for loop to insert upper case alphabet to a list box
  • 9. private void button1_Click(object sender, EventArgs e) { for(int i=100;i>=0;i--) { listBox1.Items.Add(i.ToString()); } } EXAMPLE 5 Use for loop to insert numbers from 100 to 1 to a list box
  • 10. private void button1_Click(object sender, EventArgs e) { for (int i=1;i<=100;i++) { if(i%2==0) { listBox1.Items.Add(i.ToString()); } } } EXAMPLE 6 Use for loop to insert even numbers from 1 to 100 to a list box
  • 11. private void button1_Click(object sender, EventArgs e) { for (int i=0;i<=100;i++) { if(i%5==0) { listBox1.Items.Add(i.ToString()); } } } EXAMPLE 7 Using for loop insert {0,5,10,15,20,15,30,35,…..100}to listbox private void button1_Click(object sender, EventArgs e) { for (int i=0;i<=100;i++) { listBox1.Items.Add(i.ToString()); } }
  • 12. while(condition) { statement(s); } The while statement continually executes a block of statements until a specified expression evaluates to false . The expression is evaluated each time the loop is encountered and the evaluation result is true, the loop body statements are executed. WHILE LOOP
  • 13. private void button1_Click(object sender, EventArgs e) { int i = 0; while(i<=4) { MessageBox.Show("hello"); i++; } } EXAMPLE 8 Use while loop to show hello 5 times
  • 14. private void button1_Click(object sender, EventArgs e) { int i = 1; while(i<=10) { if (i % 2 == 0) { listBox1.Items.Add(i.ToString()); } i++; } } EXAMPLE 9 Use while loop to add even number 1:10 to list box
  • 15. Do { statement(s); } while(condition) The Do while statement continually executes a block of statements until a specified expression evaluates to false . The expression is evaluated each time the loop is encountered and the evaluation result is true, the loop body statements are executed. DO WHILE LOOP
  • 16. private void button1_Click(object sender, EventArgs e) { int i = 0; do { MessageBox.Show("hello"); i++; } while (i <= 4); } EXAMPLE 10 User Do whileto show hello 5 times in a messagebox