Lec Programming Fundamentals NO 06
Lec Programming Fundamentals NO 06
Programming Fundamentals
Lec “6”
Prepared by : Dr. Wathq Ahmed Ali Kawelah
Main
Points
Flow Control:
1. The if Statement.
2. The switch Statement.
The if Statement
1. The if Statement : is a far more versatile and useful way to make decisions.
The basic structure of a if statement is as follows:
Looping
• Looping is refers to the repeated execution of statements.
1. do loop : The code you have marked out for looping is executed, a Boolean test is
perform he structure of a do loop is as follows, where < Test
Interrupting Loops
• Sometimes you want more control over the processing of looping code.
• C# provides four commands to help you here.
Interrupting Loops
Example “17”
11/28/2023 Prepared by : Dr. Wathq Ahmed Ali Kawelah Wathq@2023 24
int i = 1; while int i = 1; while
(i <= 10) (i <= 10)
{ if (i == { if (i == 6)
6) break; goto
Console.WriteLine("{0}" exitPoint;
Console.WriteLine("{0}", i++);
}
Console.WriteLine("This code will never be reached."); exitPoint:
int i;
Console.WriteLine("This code is run when the loop is exited using goto.");
for (i = 1; i <= 10; i++)
{
if ((i % 2) == 0) continue
Console.WriteLine(i);
}