lecture_08-Slides_6_per_page

# For 2 1 forx0 x2 x printfxdnx x0 x1 1 x0 x0 5 252014

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: = 0; while(x &lt; 2) { printf(“x=%d\n”,x); x = x + 1; } vs. for while 1 for(x=0; x&lt;2; x++) { printf(“x=%d\n”,x); } vs. for 2 1 for(x=0; x&lt;2; x++) { printf(“x=%d\n”,x); } 2 x0 x2 x=0 x=1 while vs. for for(x=0; x&lt;2; x++) { printf(“x=%d\n”,x); } while 2 vs. for 2 1 for(x=0; x&lt;2; x++) { printf(“x=%d\n”,x); } x0 x1 1 x=0 x=0 5 2/5/2014 while vs. for for(x=0; x&lt;2; x++) { printf(“x=%d\n”,x); } while vs. for 2 1 for(x=0; x&lt;2; x++) { printf(“x=%d\n”,x); } 2 x1 x2 1 x=0 x=1 while x=0 x=1 vs. for for(x=0; x&lt;2; x++) { printf(“x=%d\n”,x); } x2 x=0 x=1 while x = 0; while(x &lt; 2) { printf(“x=%d\n”,x); x = x + 1; } vs. for for(x=0; x&lt;2; x++) { printf(“x=%d\n”,x); } x2 x2 x=0 x=1 x=0 x=1 Quiz Time Quiz Time Which loop structure is a better conceptual match for the task? Keep playing a game until the player gains 100 points. Which loop structure is a better conceptual match for the task? Keep playing a game until the player takes 100 turns. a) while b) for c) both are equivalent a) while b) for c) both are equivalent 6 2/5/2014 Nested loops are often used to traverse Ndimensional spaces Can you figure out what this code does? for(jj = 0; jj &lt;= 10; jj++) printf(&quot;%5d&quot;, jj); printf(&quot;\n&quot;); for(ii = 1; ii &lt;= 10; ii++){ printf(&quot;%5d&quot;, ii); for(jj = 1; jj &lt;= 10; jj++){ printf(&quot;%5d&quot;, ii*jj); } printf(&quot;\n&quot;); } Quiz Time How many times will the printf statement be executed? for(ii = 0; ii &lt; 5; ii++) { for(jj = 0; jj &lt; 10; jj++){ printf(&quot;%d&quot;, ii*jj); } } a) b) c) d) 15 17 50 66 7...
View Full Document

Ask a homework question - tutors are online