It is used to take decision based on a single condition
Syntax:
False
True

If condition is True; control will enter the i...
Flow Chart:
True

False
Example: Read marks from user and state only if user is pass.
It is used to take decision based on a single condition
Syntax:
True

False
Flow Chart:
True

False
The if else statement has one condition and two statement blocksTrue block and False block
If condition is True; control w...
Example: Read marks from user and state whether student is Pass or Fail
It is used to take decision based on two conditions.
Syntax:
Flow Chart:
True

False

If within else
Example:
The Nested if can be inside the if-part or else-part
Syntax:
Flow Chart:
True

False

If within else
Flow Chart:
True

False

If within else
Example:
Example:
A switch statement is used to test many conditions
Syntax:
Flow Chart:

Start

Variable or Expression
Case A Statements

Case A
True
False

Case B Statements

Case B
True
False

Cas...
Flow Chart:

Start

Variable or Expression
Case A
True

Case A Statements
break;

False

Case B
True

Case B Statements
br...
Example:
-Initialization
-Condition checking
-Execution
-Increment / Decrement
Entry Controlled

Exit Controlled

Condition is checked at the entry of the
loop

Condition is checked at the exit of the
...
Initialization Statement is used
to initialize a variable/ counter.
The condition statement controls
the execution of loop
The loop executes till
condition statement is true

the
The execution statements are
the main body of a loop
All action statements of loop
are written here
This section is used to
increment or decrement
the variable value
Output
1
i

Variable i in memory
Output
1
i

Variable i in memory

Condition
is True
Output
1
1
i

Variable i in memory

Check it
out here
Check it
out here

Output
1

2
i

Variable i in memory
Output
1
2
i

Variable i in memory

Condition is
checked again
Output
1
2
i

Variable i in memory

Condition
is True
Output
2
i

Variable i in memory

1
2

Check it
out here
Check it
out here
3
i

Variable i in memory

Output
1
2
Output
3
i

Variable i in memory

1
2

Condition is
checked again
Output
3
i

Variable i in memory

1
2

Condition
is True
Output
3
i

Variable i in memory

1
2
3

Check it
out here
Check it
out here
4
i

Variable i in memory

Output
1
2
3
Output
4
i

Variable i in memory

1
2
3

Condition is
checked again
Output
4
i

Variable i in memory

1
2
3

Condition
is True
Output
4
i

Variable i in memory

1
2
3
4

Check it
out here
Check it
out here
5
i

Variable i in memory

Output
1
2
3
4
Output
5
i

Variable i in memory

1
2
3
4

Condition is
checked again
This process will continue till the condition become false

Suppose value of i is 9 now
Output
9
i

Variable i in memory

1
2
3
4
5
6
7
8

Condition
is True
Output
9
i

Variable i in memory

1
2
3
4
5
6
7
8
9

Check it
out here
Check it
out here
10
i

Variable i in memory

Output
1
2
3
4
5
6
7
8
9
Output
10
i

Variable i in memory

1
2
3
4
5
6
7
8
9

Condition is
checked again
Output
10
i

Variable i in memory

1
2
3
4
5
6
7
8
9

Condition
is Still True
Output
10
i

Variable i in memory

1
2
3
4
5
6
7
8
9
10

Check it
out here
Check it
out here
11
i

Variable i in memory

Output
1
2
3
4
5
6
7
8
9
10
Output
11
i

Variable i in memory

1
2
3
4
5
6
7
8
9
10

Condition is
checked again
Output
11
i

Variable i in memory

1
2
3
4
5
6
7
8
9
10

Condition
is FALSE
Output
11
i

Variable i in memory

Skip the body of
the lop and
executes the
statement jast
after the loop

1
2
3
4
5
6
7
...
Final value of i
after the
complete loop Output
11
i

Variable i in memory

1
2
3
4
5
6
7
8
9
10
Output
11
i

Variable i in memory

1
2
3
4
5
6
7
8
9
10

Final output of
the loop
Initialization Statement is used to initialize a variable/ counter.
The condition statement controls the execution of loop
The loop executes till the condition statement is true
This section is used to increment or decrement the variable value
The execution statements are the main body of a loop
All action statements of loop are written here
Output
1
i

Variable i in memory

Initialization
Output
1
i

Variable i in memory

Condition
is True
Check it
out here
Output
1
1
i

Variable i in memory
Check it
out here

increment
Output
1

2
i

Variable i in memory
Output
1
2
i

Variable i in memory

Condition is
checked again
Output
1
2
i

Variable i in memory

Condition
is True
Output
2
i

Variable i in memory

1
2

Check it
out here
Check it
out here
3
i

Variable i in memory

Output
1
2
Output
3
i

Variable i in memory

1
2

Condition is
checked again
Output
3
i

Variable i in memory

1
2

Condition
is True
Output
3
i

Variable i in memory

1
2
3

Check it
out here
Check it
out here
4
i

Variable i in memory

Output
1
2
3
Output
4
i

Variable i in memory

1
2
3

Condition is
checked again
Output
4
i

Variable i in memory

1
2
3

Condition
is True
Output
4
i

Variable i in memory

1
2
3
4

Check it
out here
Check it
out here
5
i

Variable i in memory

Output
1
2
3
4
Output
5
i

Variable i in memory

1
2
3
4

Condition is
checked again
This process will continue till the condition become false

Suppose value of i is 9 now
Output
9
i

Variable i in memory

1
2
3
4
5
6
7
8

Condition
is True
Output
9
i

Variable i in memory

1
2
3
4
5
6
7
8
9

Check it
out here
Check it
out here
10
i

Variable i in memory

Output
1
2
3
4
5
6
7
8
9
Output
10
i

Variable i in memory

1
2
3
4
5
6
7
8
9

Condition is
checked again
Output
10
i

Variable i in memory

1
2
3
4
5
6
7
8
9

Condition
is Still True
Output
10
i

Variable i in memory

1
2
3
4
5
6
7
8
9
10

Check it
out here
Check it
out here
11
i

Variable i in memory

Output
1
2
3
4
5
6
7
8
9
10
Output
11
i

Variable i in memory

1
2
3
4
5
6
7
8
9
10

Condition is
checked again
Output
11
i

Variable i in memory

1
2
3
4
5
6
7
8
9
10

Condition
is FALSE
Output
11
i

Variable i in memory

Skip the body of
the lop and
executes the
statement just
after the loop

1
2
3
4
5
6
7
...
Final value of i
after the
complete loop Output
11
i

Variable i in memory

1
2
3
4
5
6
7
8
9
10
Output
11
i

Variable i in memory

1
2
3
4
5
6
7
8
9
10

Final output of
the loop
Initialization Statement is used
to initialize a variable/ counter.
The condition statement controls
the execution of loop
The loop executes till
condition statement is true

the
The execution statements are
the main body of a loop
All action statements of loop
are written here
This section is used to
increment or decrement
the variable value
Output
1
i

Variable i in memory
Output
1
i

Variable i in memory

No condition
checking at entry of
the loop
Output
1
1
i

Variable i in memory

Check it
out here
Check it
out here

Output
1

2
i

Variable i in memory
Output
1
2
i

Variable i in memory

Condition is
checked again
Output
1
2
i

Variable i in memory

Condition
is True
Output
2
i

Variable i in memory

1
2

Check it
out here
Check it
out here
3
i

Variable i in memory

Output
1
2
Output
3
i

Variable i in memory

1
2
Condition is
checked again
Output
3

1
2

i

Variable i in memory

Condition
is True
Output
3
i

Variable i in memory

1
2
3

Check it
out here
Check it
out here
4
i

Variable i in memory

Output
1
2
3
Output
4
i

Variable i in memory

1
2
3

Condition is
checked again
Output
4
i

Variable i in memory

1
2
3

Condition
is True
Output
4
i

Variable i in memory

1
2
3
4

Check it
out here
Check it
out here
5
i

Variable i in memory

Output
1
2
3
4
Output
5
i

Variable i in memory

1
2
3
4

Condition is
checked again
This process will continue till the condition become false

Suppose value of i is 9 now
Output
9
i

Variable i in memory

1
2
3
4
5
6
7
8

Condition
is True
Output
9
i

Variable i in memory

1
2
3
4
5
6
7
8
9

Check it
out here
Check it
out here
10
i

Variable i in memory

Output
1
2
3
4
5
6
7
8
9
Output
10
i

Variable i in memory

1
2
3
4
5
6
7
8
9

Condition is
checked again
Output
10
i

Variable i in memory

1
2
3
4
5
6
7
8
9

Condition
is Still True
Output
10
i

Variable i in memory

1
2
3
4
5
6
7
8
9
10

Check it
out here
Check it
out here
11
i

Variable i in memory

Output
1
2
3
4
5
6
7
8
9
10
Output
11
i

Variable i in memory

1
2
3
4
5
6
7
8
9
10

Condition is
checked again
Output
11
i

Variable i in memory

1
2
3
4
5
6
7
8
9
10

Condition
is FALSE
Output
1
11
2
3
i
4
5
Variable i in memory
6
7
Stop the
8
execution of the
9
loop and
10
executes the
statement just
after...
Final value of i
after the
complete loop Output
11
i

Variable i in memory

1
2
3
4
5
6
7
8
9
10
Output
11
i

Variable i in memory

1
2
3
4
5
6
7
8
9
10

Final output of
the loop
 java programming- control statements
 java programming- control statements
 java programming- control statements
 java programming- control statements
 java programming- control statements
 java programming- control statements
 java programming- control statements
 java programming- control statements
 java programming- control statements
 java programming- control statements
 java programming- control statements
 java programming- control statements
 java programming- control statements
 java programming- control statements
 java programming- control statements
 java programming- control statements
 java programming- control statements
 java programming- control statements
Upcoming SlideShare
Loading in...5
×

java programming- control statements

286
-1

Published on

control statements of java

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
286
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
34
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

java programming- control statements

  1. 1. It is used to take decision based on a single condition Syntax: False True If condition is True; control will enter the if block If condition is False; control will execute statement followed by if block
  2. 2. Flow Chart: True False
  3. 3. Example: Read marks from user and state only if user is pass.
  4. 4. It is used to take decision based on a single condition Syntax: True False
  5. 5. Flow Chart: True False
  6. 6. The if else statement has one condition and two statement blocksTrue block and False block If condition is True; control will execute the statement in the true block If condition is False; control will execute the statement in false block
  7. 7. Example: Read marks from user and state whether student is Pass or Fail
  8. 8. It is used to take decision based on two conditions. Syntax:
  9. 9. Flow Chart: True False If within else
  10. 10. Example:
  11. 11. The Nested if can be inside the if-part or else-part Syntax:
  12. 12. Flow Chart: True False If within else
  13. 13. Flow Chart: True False If within else
  14. 14. Example:
  15. 15. Example:
  16. 16. A switch statement is used to test many conditions Syntax:
  17. 17. Flow Chart: Start Variable or Expression Case A Statements Case A True False Case B Statements Case B True False Case C Statements … True False default End Default Statements
  18. 18. Flow Chart: Start Variable or Expression Case A True Case A Statements break; False Case B True Case B Statements break; False … True Case C Statements break; False default End Default Statements
  19. 19. Example:
  20. 20. -Initialization -Condition checking -Execution -Increment / Decrement
  21. 21. Entry Controlled Exit Controlled Condition is checked at the entry of the loop Condition is checked at the exit of the loop If condition is initially false, the loop never executes If condition is initially false, then also the loop executes at least once i=1; while(i==0) { System.out.println(“In While loop”); } System.out.println(“out of the loop”); i=1; do { System.out.println(“In While loop”); } while(i==0); System.out.println(“out of the loop”); Output: Out of the loop Output: In while loop Out of the loop Example- for, while Example – do-while
  22. 22. Initialization Statement is used to initialize a variable/ counter.
  23. 23. The condition statement controls the execution of loop The loop executes till condition statement is true the
  24. 24. The execution statements are the main body of a loop All action statements of loop are written here
  25. 25. This section is used to increment or decrement the variable value
  26. 26. Output 1 i Variable i in memory
  27. 27. Output 1 i Variable i in memory Condition is True
  28. 28. Output 1 1 i Variable i in memory Check it out here
  29. 29. Check it out here Output 1 2 i Variable i in memory
  30. 30. Output 1 2 i Variable i in memory Condition is checked again
  31. 31. Output 1 2 i Variable i in memory Condition is True
  32. 32. Output 2 i Variable i in memory 1 2 Check it out here
  33. 33. Check it out here 3 i Variable i in memory Output 1 2
  34. 34. Output 3 i Variable i in memory 1 2 Condition is checked again
  35. 35. Output 3 i Variable i in memory 1 2 Condition is True
  36. 36. Output 3 i Variable i in memory 1 2 3 Check it out here
  37. 37. Check it out here 4 i Variable i in memory Output 1 2 3
  38. 38. Output 4 i Variable i in memory 1 2 3 Condition is checked again
  39. 39. Output 4 i Variable i in memory 1 2 3 Condition is True
  40. 40. Output 4 i Variable i in memory 1 2 3 4 Check it out here
  41. 41. Check it out here 5 i Variable i in memory Output 1 2 3 4
  42. 42. Output 5 i Variable i in memory 1 2 3 4 Condition is checked again
  43. 43. This process will continue till the condition become false Suppose value of i is 9 now
  44. 44. Output 9 i Variable i in memory 1 2 3 4 5 6 7 8 Condition is True
  45. 45. Output 9 i Variable i in memory 1 2 3 4 5 6 7 8 9 Check it out here
  46. 46. Check it out here 10 i Variable i in memory Output 1 2 3 4 5 6 7 8 9
  47. 47. Output 10 i Variable i in memory 1 2 3 4 5 6 7 8 9 Condition is checked again
  48. 48. Output 10 i Variable i in memory 1 2 3 4 5 6 7 8 9 Condition is Still True
  49. 49. Output 10 i Variable i in memory 1 2 3 4 5 6 7 8 9 10 Check it out here
  50. 50. Check it out here 11 i Variable i in memory Output 1 2 3 4 5 6 7 8 9 10
  51. 51. Output 11 i Variable i in memory 1 2 3 4 5 6 7 8 9 10 Condition is checked again
  52. 52. Output 11 i Variable i in memory 1 2 3 4 5 6 7 8 9 10 Condition is FALSE
  53. 53. Output 11 i Variable i in memory Skip the body of the lop and executes the statement jast after the loop 1 2 3 4 5 6 7 8 9 10
  54. 54. Final value of i after the complete loop Output 11 i Variable i in memory 1 2 3 4 5 6 7 8 9 10
  55. 55. Output 11 i Variable i in memory 1 2 3 4 5 6 7 8 9 10 Final output of the loop
  56. 56. Initialization Statement is used to initialize a variable/ counter.
  57. 57. The condition statement controls the execution of loop The loop executes till the condition statement is true
  58. 58. This section is used to increment or decrement the variable value
  59. 59. The execution statements are the main body of a loop All action statements of loop are written here
  60. 60. Output 1 i Variable i in memory Initialization
  61. 61. Output 1 i Variable i in memory Condition is True
  62. 62. Check it out here Output 1 1 i Variable i in memory
  63. 63. Check it out here increment Output 1 2 i Variable i in memory
  64. 64. Output 1 2 i Variable i in memory Condition is checked again
  65. 65. Output 1 2 i Variable i in memory Condition is True
  66. 66. Output 2 i Variable i in memory 1 2 Check it out here
  67. 67. Check it out here 3 i Variable i in memory Output 1 2
  68. 68. Output 3 i Variable i in memory 1 2 Condition is checked again
  69. 69. Output 3 i Variable i in memory 1 2 Condition is True
  70. 70. Output 3 i Variable i in memory 1 2 3 Check it out here
  71. 71. Check it out here 4 i Variable i in memory Output 1 2 3
  72. 72. Output 4 i Variable i in memory 1 2 3 Condition is checked again
  73. 73. Output 4 i Variable i in memory 1 2 3 Condition is True
  74. 74. Output 4 i Variable i in memory 1 2 3 4 Check it out here
  75. 75. Check it out here 5 i Variable i in memory Output 1 2 3 4
  76. 76. Output 5 i Variable i in memory 1 2 3 4 Condition is checked again
  77. 77. This process will continue till the condition become false Suppose value of i is 9 now
  78. 78. Output 9 i Variable i in memory 1 2 3 4 5 6 7 8 Condition is True
  79. 79. Output 9 i Variable i in memory 1 2 3 4 5 6 7 8 9 Check it out here
  80. 80. Check it out here 10 i Variable i in memory Output 1 2 3 4 5 6 7 8 9
  81. 81. Output 10 i Variable i in memory 1 2 3 4 5 6 7 8 9 Condition is checked again
  82. 82. Output 10 i Variable i in memory 1 2 3 4 5 6 7 8 9 Condition is Still True
  83. 83. Output 10 i Variable i in memory 1 2 3 4 5 6 7 8 9 10 Check it out here
  84. 84. Check it out here 11 i Variable i in memory Output 1 2 3 4 5 6 7 8 9 10
  85. 85. Output 11 i Variable i in memory 1 2 3 4 5 6 7 8 9 10 Condition is checked again
  86. 86. Output 11 i Variable i in memory 1 2 3 4 5 6 7 8 9 10 Condition is FALSE
  87. 87. Output 11 i Variable i in memory Skip the body of the lop and executes the statement just after the loop 1 2 3 4 5 6 7 8 9 10
  88. 88. Final value of i after the complete loop Output 11 i Variable i in memory 1 2 3 4 5 6 7 8 9 10
  89. 89. Output 11 i Variable i in memory 1 2 3 4 5 6 7 8 9 10 Final output of the loop
  90. 90. Initialization Statement is used to initialize a variable/ counter.
  91. 91. The condition statement controls the execution of loop The loop executes till condition statement is true the
  92. 92. The execution statements are the main body of a loop All action statements of loop are written here
  93. 93. This section is used to increment or decrement the variable value
  94. 94. Output 1 i Variable i in memory
  95. 95. Output 1 i Variable i in memory No condition checking at entry of the loop
  96. 96. Output 1 1 i Variable i in memory Check it out here
  97. 97. Check it out here Output 1 2 i Variable i in memory
  98. 98. Output 1 2 i Variable i in memory Condition is checked again
  99. 99. Output 1 2 i Variable i in memory Condition is True
  100. 100. Output 2 i Variable i in memory 1 2 Check it out here
  101. 101. Check it out here 3 i Variable i in memory Output 1 2
  102. 102. Output 3 i Variable i in memory 1 2 Condition is checked again
  103. 103. Output 3 1 2 i Variable i in memory Condition is True
  104. 104. Output 3 i Variable i in memory 1 2 3 Check it out here
  105. 105. Check it out here 4 i Variable i in memory Output 1 2 3
  106. 106. Output 4 i Variable i in memory 1 2 3 Condition is checked again
  107. 107. Output 4 i Variable i in memory 1 2 3 Condition is True
  108. 108. Output 4 i Variable i in memory 1 2 3 4 Check it out here
  109. 109. Check it out here 5 i Variable i in memory Output 1 2 3 4
  110. 110. Output 5 i Variable i in memory 1 2 3 4 Condition is checked again
  111. 111. This process will continue till the condition become false Suppose value of i is 9 now
  112. 112. Output 9 i Variable i in memory 1 2 3 4 5 6 7 8 Condition is True
  113. 113. Output 9 i Variable i in memory 1 2 3 4 5 6 7 8 9 Check it out here
  114. 114. Check it out here 10 i Variable i in memory Output 1 2 3 4 5 6 7 8 9
  115. 115. Output 10 i Variable i in memory 1 2 3 4 5 6 7 8 9 Condition is checked again
  116. 116. Output 10 i Variable i in memory 1 2 3 4 5 6 7 8 9 Condition is Still True
  117. 117. Output 10 i Variable i in memory 1 2 3 4 5 6 7 8 9 10 Check it out here
  118. 118. Check it out here 11 i Variable i in memory Output 1 2 3 4 5 6 7 8 9 10
  119. 119. Output 11 i Variable i in memory 1 2 3 4 5 6 7 8 9 10 Condition is checked again
  120. 120. Output 11 i Variable i in memory 1 2 3 4 5 6 7 8 9 10 Condition is FALSE
  121. 121. Output 1 11 2 3 i 4 5 Variable i in memory 6 7 Stop the 8 execution of the 9 loop and 10 executes the statement just after the loop
  122. 122. Final value of i after the complete loop Output 11 i Variable i in memory 1 2 3 4 5 6 7 8 9 10
  123. 123. Output 11 i Variable i in memory 1 2 3 4 5 6 7 8 9 10 Final output of the loop
  1. ¿Le ha llamado la atención una diapositiva en particular?

    Recortar diapositivas es una manera útil de recopilar información importante para consultarla más tarde.

×