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

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: = 0; while(x < 2) { printf(“x=%d\n”,x); x = x + 1; } vs. for while 1 for(x=0; x<2; x++) { printf(“x=%d\n”,x); } vs. for 2 1 for(x=0; x<2; x++) { printf(“x=%d\n”,x); } 2 x0 x2 x=0 x=1 while vs. for for(x=0; x<2; x++) { printf(“x=%d\n”,x); } while 2 vs. for 2 1 for(x=0; x<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<2; x++) { printf(“x=%d\n”,x); } while vs. for 2 1 for(x=0; x<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<2; x++) { printf(“x=%d\n”,x); } x2 x=0 x=1 while x = 0; while(x < 2) { printf(“x=%d\n”,x); x = x + 1; } vs. for for(x=0; x<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 <= 10; jj++) printf("%5d", jj); printf("\n"); for(ii = 1; ii <= 10; ii++){ printf("%5d", ii); for(jj = 1; jj <= 10; jj++){ printf("%5d", ii*jj); } printf("\n"); } Quiz Time How many times will the printf statement be executed? for(ii = 0; ii < 5; ii++) { for(jj = 0; jj < 10; jj++){ printf("%d", ii*jj); } } a) b) c) d) 15 17 50 66 7...
View Full Document

Ask a homework question - tutors are online