C Programming
C Programming
com
Topics
y if else statements y switch y Loops: y for y while y do while y goto y break y continue y Operators
2
Repetition Statements
y For y while y do while y goto
num
Example of Repetition
int num; for (num = 1; num <= 3; num++) cout << num << Potato << endl; // this is similar as printf( %d\n ,num);
OUTPUT
num
Example of Repetition
int num; for (num = 1; num <= 3; num++) cout << num << Potato << endl;
OUTPUT
num
Example of Repetition
true
int num;
for(num = 1; num <= 3; num++) cout << num << Potato << endl;
OUTPUT
num
Example of Repetition
int num; for (num = 1; num <= 3; num++) cout << num << Potato << endl;
OUTPUT
1Potato
num
Example of Repetition
int num; for (num = 1; num <= 3; num++) cout << num << Potato << endl;
OUTPUT
1Potato
num
Example of Repetition
true
int num;
for(num = 1; num <= 3; num++) cout << num << Potato << endl;
OUTPUT
1Potato
10
num
Example of Repetition
int num; for (num = 1; num <= 3; num++) cout << num << Potato << endl;
OUTPUT
1Potato 2Potato
11
num
Example of Repetition
int num; for (num = 1; num <= 3; num++) cout << num << Potato << endl;
OUTPUT
1Potato 2Potato
12
num
Example of Repetition
true
int num;
for(num = 1; num <= 3; num++) cout << num << Potato << endl;
OUTPUT
1Potato 2Potato
13
num
Example of Repetition
int num; for(num = 1; num <= 3; num++) cout << num << Potato << endl;
OUTPUT
num
Example of Repetition
int num; for (num = 1; num <= 3; num++) cout << num << Potato << endl;
OUTPUT
num
Example of Repetition
false
int num;
for(num = 1; num <= 3; num++) cout << num << Potato << endl;
OUTPUT
num
Example of Repetition
false
int num;
for(num = 1; num <= 3; num++) cout << num << Potato << endl;
When the loop control condition is evaluated and has value false, the loop is said to be satisfied and control passes to the statement following the For statement
17
Output
The output was 1Potato 2Potato 3Potato
18
What is output?
int count; for (count = 0; count < 10; count++) { cout << *; }
19
Answer
**********
20
21
Count-controlled loop
int count; count = 1; while ( count <= 4 ) { count
OUTPUT
22
Table for 2
2x1=2 2x2=4 2x3=6 : : 2 x 10 = 20
int main() { int year; scanf("Enter any year %d ,&year) = "; if(year%4==0) printf("YES! It is a Leap Year\n ); else printf( No! it is not a Leap Year\n ); return 0; }
25
Repetition Structures
while repetition structure
Continues indefinitely as long as the condition is true
product = 2; while (product <= 1000) product *= 2;
product *= 2
false
26
count
OUTPUT
27
count
OUTPUT
28
count
OUTPUT count is 1
29
count
OUTPUT count is 1
30
count
OUTPUT count is 1
31
count
cout<< count is << count ; count++; } cout<< Done ; OUTPUT count is 1 count is 2
32
count
33
count
34
count
35
count
36
count
cout<< count is << count ; count++; } cout<< Done ; OUTPUT count is 1 count is 2 count is 3
37
count
38
count
39
count
40
count
41
While Loop
while ( c != y ) { } test expression
42
Repetition Structures
do/while repetition structure
Loop body is executed at least once do { statement while (condition);
43
Print counter
++counter <= 10
false
44
46
what is Continue ?
y What is Continue Statement ? When and How do
we use it????
47
continue Statement
y The continue statement causes the program to skip the
rest of the loop in the current iteration as if the end of the statement block had been reached, causing it to jump to the start of the following iteration.
goto statement
y goto allows to make an absolute jump to another
point in the program. You should use this feature with caution since its execution causes an unconditional jump ignoring any type of nesting limitations. y The destination point is identified by a label, which is then used as an argument for the goto statement. y A label is made of a valid identifier followed by a colon (:).
Operators
y ++ y -y += y -= y *= y %= y &&
+ -
* % ||
52
Escape Characters
Escape Sequence \n \t \\ \ \ Working New Line Tab Backslash Double quotation mark Single Code