Pemrograman Komputer Pertemuan 06 Repetition Bambang Heru Iswanto, Dr.rer.nat M.Si <ul><li>Jurusan Fisika </li></ul><ul><l...
Learning Outcomes <ul><li>Pada akhir pertemuan ini, diharapkan mahasiswa  </li></ul><ul><li>akan mampu : </li></ul><ul><li...
Outline Materi <ul><li>The Do … Loop Structure </li></ul><ul><li>The For…Next Loop Structure </li></ul><ul><li>Nested Loop...
The Do … Loop Structure <ul><li>Syntax and Action of the Do…Loop </li></ul><ul><ul><li>Do </li></ul></ul><ul><ul><li>state...
The Do … Loop Structure <ul><li>Do While…Loop </li></ul><ul><ul><li>Do While  condition </li></ul></ul><ul><ul><li>stateme...
The Do … Loop Structure <ul><li>Coding the Loop Body </li></ul><ul><ul><li>One or more statements in the loop body must ev...
The Do … Loop Structure <ul><li>Do Loop…While </li></ul><ul><ul><li>Works like the Do While…Loop. </li></ul></ul><ul><ul><...
The Do … Loop Structure <ul><li>Do Until…Loop and Do…Loop Until </li></ul><ul><ul><li>Do Until…Loop </li></ul></ul><ul><ul...
The For…Next Loop Structure <ul><li>Syntax and Action of For…Next </li></ul><ul><ul><li>For  counter  =  start  To  end </...
The For…Next Loop Structure <ul><li>The Step Amount </li></ul><ul><ul><li>Counter variable may be incremented by a step am...
Nested Loops <ul><li>Loops may be embedded inside of other loops. </li></ul><ul><li>Nested Do While…Loops </li></ul><ul><u...
TERIMA KASIH 01/02/11 ©  2010 Universitas Negeri Jakarta  |  www.unj.ac.id  |
Upcoming SlideShare
Loading in...5
×

Pemrograman komputer 6 (repetisi)

632

Published on

unj fmipa-fisika

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

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

No notes for slide

Transcript of "Pemrograman komputer 6 (repetisi)"

  1. 1. Pemrograman Komputer Pertemuan 06 Repetition Bambang Heru Iswanto, Dr.rer.nat M.Si <ul><li>Jurusan Fisika </li></ul><ul><li>Fakultas Matematika dan Ilmu Pengetahuan Alam </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  2. 2. Learning Outcomes <ul><li>Pada akhir pertemuan ini, diharapkan mahasiswa </li></ul><ul><li>akan mampu : </li></ul><ul><li>Mendemonstrasikan penggunaan perintah pengulangan </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  3. 3. Outline Materi <ul><li>The Do … Loop Structure </li></ul><ul><li>The For…Next Loop Structure </li></ul><ul><li>Nested Loops </li></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  4. 4. The Do … Loop Structure <ul><li>Syntax and Action of the Do…Loop </li></ul><ul><ul><li>Do </li></ul></ul><ul><ul><li>statementblock </li></ul></ul><ul><ul><li>Loop </li></ul></ul><ul><li>Run Time: The Effect of the Do…Loop Structure </li></ul><ul><ul><li>Statements in a loop’s interior are executed one at a time. </li></ul></ul><ul><ul><li>The Do marks the top of the loop. </li></ul></ul><ul><ul><li>The Loop sends the execution back to the top. </li></ul></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  5. 5. The Do … Loop Structure <ul><li>Do While…Loop </li></ul><ul><ul><li>Do While condition </li></ul></ul><ul><ul><li>statementblock </li></ul></ul><ul><ul><li>Loop </li></ul></ul><ul><li>Run Time: The Effect of the Do While…Loop Structure </li></ul><ul><ul><li>Loop continues to execute “while the condition is true.” </li></ul></ul><ul><ul><li>Loop is exited when the condition is false. </li></ul></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  6. 6. The Do … Loop Structure <ul><li>Coding the Loop Body </li></ul><ul><ul><li>One or more statements in the loop body must eventually cause the condition to become false. </li></ul></ul><ul><ul><li>Order of statements inside loop affects the result of the loop. </li></ul></ul><ul><ul><li>Loop may terminate immediately. </li></ul></ul><ul><ul><li>Loop can be viewed as a meta statement. </li></ul></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  7. 7. The Do … Loop Structure <ul><li>Do Loop…While </li></ul><ul><ul><li>Works like the Do While…Loop. </li></ul></ul><ul><ul><li>Termination at the bottom of the loop. </li></ul></ul><ul><ul><li>Syntax: </li></ul></ul><ul><ul><ul><li>Do </li></ul></ul></ul><ul><ul><ul><ul><li>statementblock </li></ul></ul></ul></ul><ul><ul><ul><li>Loop While condition </li></ul></ul></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  8. 8. The Do … Loop Structure <ul><li>Do Until…Loop and Do…Loop Until </li></ul><ul><ul><li>Do Until…Loop </li></ul></ul><ul><ul><ul><li>Termination condition at the top of the loop. </li></ul></ul></ul><ul><ul><ul><li>Same syntax and action as the Do While…Loop. </li></ul></ul></ul><ul><ul><ul><ul><li>Except: </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>Difference in keywords. </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>Loop statements inside the Do Until…Loop are executed when the conditions are False. </li></ul></ul></ul></ul></ul><ul><ul><li>Do…Loop Until </li></ul></ul><ul><ul><ul><li>Termination condition at the bottom of the loop. </li></ul></ul></ul><ul><ul><ul><li>Exit when the condition is True. </li></ul></ul></ul><ul><li>Initialization and Termination </li></ul><ul><ul><ul><li>Loops may start or end at the wrong place. </li></ul></ul></ul><ul><ul><ul><ul><li>The initialization statement may be off. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>The condition operator may need to be changed. </li></ul></ul></ul></ul><ul><ul><ul><ul><li>The order of statements within the loop may need to be changed. </li></ul></ul></ul></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  9. 9. The For…Next Loop Structure <ul><li>Syntax and Action of For…Next </li></ul><ul><ul><li>For counter = start To end </li></ul></ul><ul><ul><ul><li>statementblock </li></ul></ul></ul><ul><ul><li>Next </li></ul></ul><ul><ul><li>Run Time: The Effect of the For…Next Structure </li></ul></ul><ul><ul><ul><li>Counter variable and start and end expressions must be evaluated to control the number of times the loop will be processed. </li></ul></ul></ul><ul><li>For…Next versus Do…Loop Variations </li></ul><ul><ul><li>Use a For…Next loop when the number of loop iterations can be determined. </li></ul></ul><ul><ul><li>Use a Do…Loop variety only when the number of iterations depends on the results of statements inside the loop. </li></ul></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  10. 10. The For…Next Loop Structure <ul><li>The Step Amount </li></ul><ul><ul><li>Counter variable may be incremented by a step amount, such 3 instead of 1. </li></ul></ul><ul><ul><li>Syntax: </li></ul></ul><ul><ul><ul><li>For counter = start To end Step increment </li></ul></ul></ul><ul><ul><ul><ul><li>statementblock </li></ul></ul></ul></ul><ul><ul><ul><li>Next </li></ul></ul></ul><ul><li>Avoiding For…Next Errors </li></ul><ul><ul><li>Do not place statements inside the loop that change start , end , and increment expressions. </li></ul></ul><ul><ul><li>Do not change the counter variable inside the loop. </li></ul></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  11. 11. Nested Loops <ul><li>Loops may be embedded inside of other loops. </li></ul><ul><li>Nested Do While…Loops </li></ul><ul><ul><li>Do While condition1 </li></ul></ul><ul><ul><ul><li>statementblock1a </li></ul></ul></ul><ul><ul><ul><li>Do While condition2 </li></ul></ul></ul><ul><ul><ul><li>statementblock2 </li></ul></ul></ul><ul><ul><ul><li>Loop </li></ul></ul></ul><ul><ul><ul><ul><li>statementblock1b </li></ul></ul></ul></ul><ul><ul><ul><li>Loop </li></ul></ul></ul><ul><li>Nested For…Next Loops </li></ul><ul><ul><li>For counter1 = start1 To end1 </li></ul></ul><ul><ul><ul><li>statementblock1a </li></ul></ul></ul><ul><ul><ul><li>For counter2 = start2 To end2 </li></ul></ul></ul><ul><ul><ul><li>statementblock2 </li></ul></ul></ul><ul><ul><ul><li>Next </li></ul></ul></ul><ul><ul><ul><ul><li>statementblock1b </li></ul></ul></ul></ul><ul><ul><ul><li>Next </li></ul></ul></ul>01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |
  12. 12. TERIMA KASIH 01/02/11 © 2010 Universitas Negeri Jakarta | www.unj.ac.id |

×