cmsc 150 loops cs 150: fri 20 jan 2012. representing dna agtccagtgtcaa
DESCRIPTION
Start Codon: ATGTRANSCRIPT
![Page 1: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/1.jpg)
CMSC 150LOOPS
CS 150: Fri 20 Jan 2012
![Page 2: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/2.jpg)
Representing DNA
AGTCCAGTGTCAA
![Page 3: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/3.jpg)
Start Codon: ATG
![Page 4: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/4.jpg)
Start Codon: ATG
![Page 5: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/5.jpg)
Consider in JavaString dna = “AGTCCAGTGTCAA”;
![Page 6: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/6.jpg)
Consider in JavaString dna = “AGTCCAGTGTCAA”;
if ( dna.substring(0,3).equals(“ATG”) )
![Page 7: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/7.jpg)
String dna = “AGTCCAGTGTCAA”;
if ( dna.substring(0,3).equals(“ATG”) )if ( dna.substring(1,4).equals(“ATG”) )
Consider in Java
![Page 8: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/8.jpg)
String dna = “AGTCCAGTGTCAA”;
if ( dna.substring(0,3).equals(“ATG”) )if ( dna.substring(1,4).equals(“ATG”) )if ( dna.substring(2,5).equals(“ATG”) )
Consider in Java
![Page 9: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/9.jpg)
Consider in JavaString dna = “AGTCCAGTGTCAA”;
if ( dna.substring(0,3).equals(“ATG”) )if ( dna.substring(1,4).equals(“ATG”) )if ( dna.substring(2,5).equals(“ATG”) )if ( dna.substring(3,6).equals(“ATG”) )if ( dna.substring(4,7).equals(“ATG”) )...if ( dna.substring(10,12).equals(“ATG”) )
![Page 10: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/10.jpg)
Loops
![Page 11: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/11.jpg)
Loop Syntax
while ( condition ) {
statement; }
for ( initialization; condition; update )
{
statement; }
![Page 12: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/12.jpg)
Loop Syntax
while ( condition ) {
statement; }
for ( initialization; condition; update )
{
statement; }
Use while when you
don’t know in advance
the # of times to loop
![Page 13: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/13.jpg)
Loop Syntax
while ( condition ) {
statement; }
for ( initialization; condition; update )
{
statement; }
Use for when you know in advance the # of times to
loop
![Page 14: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/14.jpg)
While Loop Syntax while ( condition ) {
statement_to_execute; }
build a condition that eventually becomes false need statement w/in body to advance toward false
condition evaluated each time before executing statement
![Page 15: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/15.jpg)
While Loop Example while ( condition ) {
statement_to_execute; }
int count = 0; while ( count < 3 ) { System.out.println( “count = “ + count); count++;}
![Page 16: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/16.jpg)
While Loop Actionint count = 0;
while ( count < 3 )
{System.out.println( “count = “ + count );count++;
}
1. initialize count to 0
![Page 17: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/17.jpg)
While Loop Actionint count = 0;
while ( count < 3 )
{System.out.println( “count = “ + count );count++;
}
1. initialize count to 02. evaluate condition: count < 3 is true, so…
![Page 18: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/18.jpg)
While Loop Actionint count = 0;
while ( count < 3 )
{System.out.println( “count = “ + count );count++;
}
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints count = 0
![Page 19: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/19.jpg)
While Loop Actionint count = 0;
while ( count < 3 )
{System.out.println( “count = “ + count );count++;
}
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints count = 04. execute statement: increment count to 1
![Page 20: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/20.jpg)
While Loop Actionint count = 0;
while ( count < 3 )
{System.out.println( “count = “ + count );count++;
}
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints count = 04. execute statement: increment count to 15. evaluate condition: count < 3 is true, so…
![Page 21: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/21.jpg)
While Loop Actionint count = 0;
while ( count < 3 )
{System.out.println( “count = “ + count );count++;
}
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints count = 04. execute statement: increment count to 15. evaluate condition: count < 3 is true, so…6. execute statement: prints count = 1
![Page 22: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/22.jpg)
While Loop Actionint count = 0;
while ( count < 3 )
{System.out.println( “count = “ + count );count++;
}
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints count = 04. execute statement: increment count to 15. evaluate condition: count < 3 is true, so…6. execute statement: prints count = 17. execute statement: increment count to 2
![Page 23: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/23.jpg)
int count = 0;
while ( count < 3 )
{System.out.println( “count = “ + count );count++;
}
While Loop Action
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints count = 04. execute statement: increment count to 15. evaluate condition: count < 3 is true, so…6. execute statement: prints count = 17. execute statement: increment count to 28. evaluate condition: count < 3 is true, so…
![Page 24: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/24.jpg)
int count = 0;
while ( count < 3 )
{System.out.println( “count = “ + count );count++;
}
While Loop Action
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints count = 04. execute statement: increment count to 15. evaluate condition: count < 3 is true, so…6. execute statement: prints count = 17. execute statement: increment count to 28. evaluate condition: count < 3 is true, so…9. execute statement: prints count = 2
![Page 25: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/25.jpg)
int count = 0;
while ( count < 3 )
{System.out.println( “count = “ + count );count++;
}
While Loop Action
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints count = 04. execute statement: increment count to 15. evaluate condition: count < 3 is true, so…6. execute statement: prints count = 17. execute statement: increment count to 28. evaluate condition: count < 3 is true, so…9. execute statement: prints count = 210. execute statement: increment count to 3
![Page 26: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/26.jpg)
int count = 0;
while ( count < 3 )
{System.out.println( “count = “ + count );count++;
}
While Loop Action
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints count = 04. execute statement: increment count to 15. evaluate condition: count < 3 is true, so…6. execute statement: prints count = 17. execute statement: increment count to 28. evaluate condition: count < 3 is true, so…9. execute statement: prints count = 210. execute statement: increment count to 311. evaluate condition: count < 3 is false, so exit the loop
![Page 27: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/27.jpg)
For Loop Syntax for ( initialization; condition; update
) {
statement_to_execute; }
typically declare and initialize a variable for the loop: int count = 0;
executed exactly once, as loop starts
![Page 28: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/28.jpg)
For Loop Syntax
build a condition based on the loop variable thateventually becomes false
count < 3;
evaluated each time before executing statement
for ( initialization; condition; update )
{ statement_to_execute; }
![Page 29: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/29.jpg)
For Loop Syntax
statement that advances the condition toward failure count = count + 1
executed each time after executing statement
for ( initialization; condition; update )
{ statement_to_execute; }
![Page 30: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/30.jpg)
For Loop Example for ( initialization; condition; update ) {
statement_to_execute; }
for ( int count = 0; count < 3; count++ ) {
System.out.println( "Count = " + count );
}
![Page 31: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/31.jpg)
for ( initialization; condition; update ) {
statement_to_execute; }
for ( int count = 0; count < 3; count++ ) {
System.out.println( "Count = " + count );
}
For Loop Example
![Page 32: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/32.jpg)
for ( initialization; condition; update ) {
statement_to_execute; }
for ( int count = 0; count < 3; count++ ) {
System.out.println( "Count = " + count );
}
For Loop Example
![Page 33: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/33.jpg)
For Loop Actionfor ( int count = 0; count < 3; count++ )
System.out.println( "Count = " + count );
1. initialize count to 0
{}
![Page 34: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/34.jpg)
For Loop Actionfor ( int count = 0; count < 3; count++ )
System.out.println( "Count = " + count );
1. initialize count to 02. evaluate condition: count < 3 is true, so…
{}
![Page 35: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/35.jpg)
For Loop Actionfor ( int count = 0; count < 3; count++ )
System.out.println( "Count = " + count );
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints Count = 0
{}
![Page 36: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/36.jpg)
For Loop Actionfor ( int count = 0; count < 3; count++ )
System.out.println( "Count = " + count );
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints Count = 04. update: increment count to 1
{}
![Page 37: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/37.jpg)
For Loop Actionfor ( int count = 0; count < 3; count++ )
System.out.println( "Count = " + count );
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints Count = 04. update: increment count to 15. evaluate condition: count < 3 is true, so…
{}
![Page 38: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/38.jpg)
For Loop Actionfor ( int count = 0; count < 3; count++ )
System.out.println( "Count = " + count );
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints Count = 04. update: increment count to 15. evaluate condition: count < 3 is true, so…6. execute statement: prints Count = 1
{}
![Page 39: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/39.jpg)
For Loop Actionfor ( int count = 0; count < 3; count++ )
System.out.println( "Count = " + count );
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints Count = 04. update: increment count to 15. evaluate condition: count < 3 is true, so…6. execute statement: prints Count = 17. update: increment count to 2
{}
![Page 40: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/40.jpg)
For Loop Actionfor ( int count = 0; count < 3; count++ )
System.out.println( "Count = " + count );
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints Count = 04. update: increment count to 15. evaluate condition: count < 3 is true, so…6. execute statement: prints Count = 17. update: increment count to 28. evaluate condition: count < 3 is true, so…
{}
![Page 41: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/41.jpg)
For Loop Actionfor ( int count = 0; count < 3; count++ )
System.out.println( "Count = " + count );
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints Count = 04. update: increment count to 15. evaluate condition: count < 3 is true, so…6. execute statement: prints Count = 17. update: increment count to 28. evaluate condition: count < 3 is true, so…9. execute statement: prints Count = 2
{}
![Page 42: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/42.jpg)
For Loop Actionfor ( int count = 0; count < 3; count++ )
System.out.println( "Count = " + count );
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints Count = 04. update: increment count to 15. evaluate condition: count < 3 is true, so…6. execute statement: prints Count = 17. update: increment count to 28. evaluate condition: count < 3 is true, so…9. execute statement: prints Count = 210. update: increment count to 3
{}
![Page 43: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/43.jpg)
For Loop Actionfor ( int count = 0; count < 3; count++ )
System.out.println( "Count = " + count );
1. initialize count to 02. evaluate condition: count < 3 is true, so…3. execute statement: prints Count = 04. update: increment count to 15. evaluate condition: count < 3 is true, so…6. execute statement: prints Count = 17. update: increment count to 28. evaluate condition: count < 3 is true, so…9. execute statement: prints Count = 210. update: increment count to 311. evaluate condition: count < 3 is false, so exit the loop
{}
![Page 44: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/44.jpg)
What happens?for ( int count = 0; count > 3; count++ )System.out.println( "Count = " + count );
{}
![Page 45: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/45.jpg)
What happens?for ( int count = 0; count > 3; count++ )System.out.println( "Count = " + count );
{}
![Page 46: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/46.jpg)
What happens?for ( int count = 0; count < 10; count = count++)System.out.println( "Count = " + count );{
}
![Page 47: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/47.jpg)
What happens?for ( int count = 0; count < 10; count = count++)System.out.println( "Count = " + count );
infinite loop!!
because count++ returns value of count before incrementing
{}
![Page 48: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/48.jpg)
What happens?for ( int count = 0; count < 10; )System.out.println( "Count = " + count );
{}
![Page 49: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/49.jpg)
What happens?for ( int count = 0; count < 10; )System.out.println( "Count = " + count );
{}
infinite loop!!
no update, so count is always 0
![Page 50: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/50.jpg)
What happens?for ( int count = 1; count != 10; count += 2)System.out.println( "Count = " + count );
{}
![Page 51: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/51.jpg)
What happens?for ( int count = 1; count != 10; count += 2)System.out.println( "Count = " + count );
{}
![Page 52: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/52.jpg)
What happens?for ( int count = 0; count < 10; count += 2);
System.out.println( "Bill Maher" );{}
![Page 53: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/53.jpg)
What happens?for ( int count = 0; count < 10; count += 2);
System.out.println("Bill Maher" );{}
Prints only once because
of this!
![Page 54: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/54.jpg)
Equivalentfor ( int count = 0; count < 10; count += 2);
System.out.println( "Bill Maher" );{}
for ( int count = 0; count < 10; count += 2) ; // do-nothing statement
System.out.println( "Bill Maher" );
{}
![Page 55: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/55.jpg)
What happens?for ( int count = 0; count < 10; count += 2);
System.out.println( "Count = " + count );
{}
![Page 56: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/56.jpg)
What happens?for ( int count = 0; count < 10; count += 2);
System.out.println( "Count = " + count );
{}
![Page 57: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/57.jpg)
Guess the Number
![Page 58: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/58.jpg)
Start Codon: ATG
![Page 59: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/59.jpg)
While Loop or For Loop?String dna = “ATATGCCTG”;
if ( dna.substring(0,3).equals(“ATG”) )if ( dna.substring(1,4).equals(“ATG”) )if ( dna.substring(2,5).equals(“ATG”) )if ( dna.substring(3,6).equals(“ATG”) )if ( dna.substring(4,7).equals(“ATG”) )if ( dna.substring(5,8).equals(“ATG”) )if ( dna.substring(6,9).equals(“ATG”) )
![Page 60: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/60.jpg)
String dna = “ATATGCCTG”;
if ( dna.substring(0,3).equals(“ATG”) )if ( dna.substring(1,4).equals(“ATG”) )if ( dna.substring(2,5).equals(“ATG”) )if ( dna.substring(3,6).equals(“ATG”) )if ( dna.substring(4,7).equals(“ATG”) )if ( dna.substring(5,8).equals(“ATG”) )if ( dna.substring(6,9).equals(“ATG”) )
While Loop or For Loop?
![Page 61: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/61.jpg)
Building A For LoopString dna = “ATATGCCTG”;
for ( ???????; ???????; ??????? ){if ( dna.substring(i,i+3).equals(“ATG”) ){
// do something magical}
}
![Page 62: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/62.jpg)
Building A For LoopString dna = “ATATGCCTG”;
for ( ???????; ???????; ??????? ){if ( dna.substring(?,?).equals(“ATG”) ){
// do something magical}
}
![Page 63: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/63.jpg)
String dna = “ATATGCCTG”;
for ( ???????; ???????; ??????? ){if ( dna.substring(?,?).equals(“ATG”) ){
// do something magical}
}
Building A For Loop
![Page 64: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/64.jpg)
String dna = “ATATGCCTG”;
for ( int i = 0; ???????; ??????? ){if ( dna.substring(?,?).equals(“ATG”) ){
// do something magical}
}
Building A For Loop
![Page 65: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/65.jpg)
String dna = “ATATGCCTG”;
for ( int i = 0; i < 7; ??? ){if ( dna.substring(?,?).equals(“ATG”) ){
// do something magical}
}
Building A For Loop
![Page 66: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/66.jpg)
String dna = “ATATGCCTG”;
for ( int i = 0; i <= dna.length()-3; ????? ){if ( dna.substring(?,?).equals(“ATG”) ){
// do something magical}
}
Building A For Loop
![Page 67: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/67.jpg)
String dna = “ATATGCCTG”;
for ( int i = 0; i <= dna.length()-3; ????? ){if ( dna.substring(?,?).equals(“ATG”) ){
// do something magical}
}
Building A For Loop
![Page 68: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/68.jpg)
String dna = “ATATGCCTG”;
for ( int i = 0; i <= dna.length()-3; i++ ){if ( dna.substring(?,?).equals(“ATG”) ){
// do something magical}
}
Building A For Loop
![Page 69: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/69.jpg)
String dna = “ATATGCCTG”;
for ( int i = 0; i <= dna.length()-3; i++ ){if ( dna.substring(i,i+3).equals(“ATG”) ){
// do something magical}
}
Building A For Loop
![Page 70: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/70.jpg)
if ( dna.substring(0,3).equals(“ATG”) ) …
if ( dna.substring(1,4).equals(“ATG”) ) …
if ( dna.substring(2,5).equals(“ATG”) ) …
if ( dna.substring(3,6).equals(“ATG”) ) …
if ( dna.substring(4,7).equals(“ATG”) ) …
if ( dna.substring(5,8).equals(“ATG”) ) …
if ( dna.substring(6,9).equals(“ATG”) ) …
for ( int i = 0; i <= dna.length()-3; i++ )
{
if ( dna.substring(i,i+3).equals(“ATG”) ){
// do something magical
}
}
Building A For Loop
![Page 71: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/71.jpg)
for ( int i = 0; i < 7; i++ )
{
if ( dna.substring(i,i+3).equals(“ATG”) ){
// do something magical
}
}
Write An Equivalent While Loop
![Page 72: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/72.jpg)
Digital Images
![Page 73: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/73.jpg)
Digital Images
for ( int row = 0; row < image.getNumRows(); row = row + 1 ){
for ( int col = 0; col < image.getNumCols(); col = col + 1 ){
image.getPixelAt( row, col ).brightenByAmt( 10 );}
}
0
1
2
3
0 1 2 3
![Page 74: CMSC 150 LOOPS CS 150: Fri 20 Jan 2012. Representing DNA AGTCCAGTGTCAA](https://reader034.vdocuments.us/reader034/viewer/2022051304/5a4d1b6e7f8b9ab0599b4438/html5/thumbnails/74.jpg)
Digital Images
for ( int row = 0; row < image.getNumRows(); row = row + 1 ){
for ( int col = 0; col < image.getNumCols(); col = col + 1 ){
image.getPixelAt( row, col ).brightenByAmt( 10 );}
}
0
1
2
3
0 1 2 3
• row = 0, col loops through values 0…3• row = 1, col loops through values 0…3• row = 2, col loops through values 0…3• row = 3, col loops through values 0…3