// This is the master plan for the advanced topics in loops // break // Single // Nested // break statement not inside a loop or switch statement // continue // Correct // continue statement not inside a loop // Infinite // No update // Incorrect update // Moving terminal value // Assignment in condition // ... // Mixed // Multiple Dependent // Nested Dependent // Accumulator // Equivalent loops ? // // // ---------------------------------------------------- // Iteration.break.Single - 100 - 12 templates // Iteration.break.Nested - 125 - 12 templates // Iteration.break.break statement not inside a loop or switch statement - 150 - 8 templates // // Iteration.continue.Correct - 200 - 12 templates // Iteration.continue.continue statement not inside a loop - 225 - 8 templates // // Iteration.Infinite.Condition variable is not updated in the loop - 300 - 6 templates // Iteration.Infinite.Condition variable is incorrectly updated in the loop - 325 - 20 templates // Iteration.Infinite.Value against which condition variable is compared is also modified - 350 - 15 templates // Iteration.Infinite.Assignment used in condition - 375 - 6 templates // // [Iteration.Infinite.Empty condition in for loop - 400 - 3 templates] // Iteration.Logic.Pretest.Condition.Empty - 425 - 3 templates // Iteration.Logic.Posttest.Condition.Empty - 450 - 3 templates // // Iteration.Infinite.Condition is a constant - either always true or always false - 475 - 9 templates // // Iteration.Mixed.Multiple Dependent - 500 - 12 templates // Iteration.Mixed.Nested Dependent - 550 - 12 templates // // Iteration.Accumulator - 600 - 12 templates // // **** Strategy for advanced loops learning objectives ***** // Create about 12 templates for each learning objective // Designate all templates to be of Type: debug_output // Alternate templates between for loops, while loops, and do-while loops // Declare R values in templates to be of type the default type, that is, by default they will be of type "integer" // Declare T types as "integer" for variables that can clearly take on only positive values // Declare T types as "signed" for variables that appear to have possibility of being assigned a negative value // Create randomness for starting values and constraints for loop variables and for output values // Limit the number of times loop executes between 1 and 3 times // Vary the statements in the loop block // TEMPLATES CREATED BY RALPH WALDE, MARCH 25, 2010 // ------------------------------------------------------------------------ // Iteration.break.Single 100 - 124 // Unconditional break in for-loop, decrease by 1, break is last statement in block # 100 Iteration.break.Single > {(){;for( = ; > ; = - ){<< ; break;}}} > Type: debug_output Hardness: 30 // Unconditional break in while-loop, increase by 1, break is not last statement in block # 101 Iteration.break.Single > {(){=;while( < ){<< ; break; = + ;}}} > Type: debug_output Hardness: 30 // Unconditional break in do-while-loop, decrease by 2, break is last statement in block # 102 Iteration.break.Single > {(){=;do{<< ; = - ; break;}while( > );}} > Type: debug_output Hardness: 30 // Conditional break in for-loop, increase by 2, break fires on first iteration, break is last statement in loop # 105 Iteration.break.Single > {(){;for( = ; <= ; = + ){<< ; if( > ) break;}}} > Type: debug_output Hardness: 40 // Conditional break in while-loop, decrease by 1, break fires on first iteration, break is not last statement in loop # 106 Iteration.break.Single > {(){=;while( >= ){<< ; if( > ) break; = - 1;}}} > Type: debug_output Hardness: 40 // Conditional break in do-while-loop, increase by 1, break fires on first iteration, # 107 Iteration.break.Single > {(){=;do{ = + ; << ; if( > ) break;}while( <= );}} > Type: debug_output Hardness: 40 // Conditional break in for-loop, decrease by 1, break fires on second iteration # 110 Iteration.break.Single > // [,,]{(){;for( = ; > ; = - 1){<< ; if( <= ) break;}}} [,,,]{(){;for( = ; > ; = - ){<< ; if( <= ) break;}}} > Type: debug_output Hardness: 40 // Pretest problem // Conditional break in while-loop, increase by 2, break fires on third iteration # 111 Iteration.break.Single > // [,,]{(){=;while( < ){<< ; if( >= ) break; = + 2;}}} [,,,]{(){=;while( < ){<< ; if( >= ) break; = + ;}}} > Type: debug_output Hardness: 40 // Posttest problem // Conditional break in do-while-loop, decrease by 2, break fires on second iteration # 112 Iteration.break.Single > // [,,]{(){=;do{ << ; = - 2; if( < ) break;}while( > );}} [,,,]{(){=;do{ << ; = - ; if( <= ) break;}while( > );}} > Type: debug_output Hardness: 40 // Conditional break in for-loop, increase by 1, break fires after a random number of iterations # 115 Iteration.break.Single > [,]{(){;for( = ; < ; = + 1){<< ; if( == ) break;}}} > Type: debug_output Hardness: 40 // Conditional break in while-loop, decrease by 1, finishes after 3 iterations, break fires after random number of iterations # 116 Iteration.break.Single > {(){=;while( > ){ = - 1; << ; if( % 5 == 0 ) break;}}} > Type: debug_output Hardness: 40 // Condition is true // Problems 120-123 added 4/4/10 by Ralph Walde // Conditional break in for-loop, increase by 1, iteration condition is the constant true # 120 Iteration.break.Single > [,]{() {;for( = ;true; = + 1){<< + 1; if( > ) break;}}} > Type: debug_output Hardness: 40 // Conditional break in while-loop, decrease by 1, iteration condition is the constant true # 121 Iteration.break.Single > [,,]{() {=;while(true){if( <= ) break; = - 1;<< ; }}} > Type: debug_output Hardness: 40 // Conditional break in do-while-loop, increase by 2, iteration condition is the constant true # 123 Iteration.break.Single > [,,]{() {=;do{ = + 2; if( >= ) break;<< ;}while(true);}} > Type: debug_output Hardness: 40 // // Conditional break in do-while-loop, increase by 2, finishes after 2 iterations, break fires after random number of iterations // # 111 // Iteration.break.Single // > // [,,]{(){=;do{ << ; if( > ) break; = + 2;}while( < );}} // > // Type: debug_output // Hardness: 40 // ------------------------------------------------------------------------ // Iteration.break.Nested 125 - 149 // Nested for-loops, conditional break in inner loop dependent on inner loop variable, breaks without any iteration of inner loop # 125 Iteration.break.Nested > // [,,,,]{(){;;for( = ; < ; = + 1){<< ;for( = ; < ; = + 1){if( < ){ break; } << ;}}}} {(){;;for( = ; < ; = + 1){<< ;for( = ; < ; = + 1){<< ;if( < ){ break; }}}}} > Type: debug_output Hardness: 40 // Nested while-loops, conditional break in inner loop dependent on inner loop variable, breaks without any iteration of inner loop # 126 Iteration.break.Nested > [,,,]{(){ = ;;while( < ){<< ; = ;while( < ){if( < ){ break; } << ; = + 1;} = + 1;}}} > Type: debug_output Hardness: 40 // Nested do-while-loops, conditional break in inner loop dependent on inner loop variable, breaks without any iteration of inner loop # 127 Iteration.break.Nested > [,,,]{(){ = ;;do{<< ; = ;do{if( > 0 ){ break; } << ; = + 1;}while( < ); = - 1;}while( > );}} > Type: debug_output Hardness: 40 // Nested for-loops, conditional break in inner loop dependent on inner loop variable, breaks with one iteration of inner loop # 130 Iteration.break.Nested > {(){;;for( = ; > ; = - 1){<< ;for( = ; < ; = + 1){if( > ){ break; } << ;}}}} > Type: debug_output Hardness: 50 // Pretest problem // Nested while-loops, conditional break in inner loop dependent on inner loop variable, breaks with one iteration of inner loop # 131 Iteration.break.Nested > [,,,]{(){ = ;;while( < ){<< ; = ;while( > ){if( < ){ break; } << ; = - 1;} = + 1;}}} > Type: debug_output Hardness: 50 // Posttest problem // Nested do-while-loops, conditional break in inner loop dependent on inner loop variable, breaks with one iteration of inner loop # 132 Iteration.break.Nested > [,,,]{(){ = ;;do{<< ; = ;do{<< ; = - 1;if( > 0 ){ break; } }while( >= ); = - 1;}while( >= );}} > Type: debug_output Hardness: 50 // Nested for-loops, conditional break in inner loop dependent on outer loop variable # 135 Iteration.break.Nested > [,]{(){;;for( = ; < ; = + 1){<< ;for( = ; < ; = + 1){if( > ){ break; } << ;}}}} > Type: debug_output Hardness: 80 // Nested while-loops, conditional break in inner loop dependent on outer loop variable # 136 Iteration.break.Nested > [,]{(){ = ;;while( > ){<< ; = ;while( > ){if( < ){ break; } << ; = - 1;} = - 1;}}} > Type: debug_output Hardness: 80 // Nested do-while-loops, conditional break in inner loop dependent on outer loop variable # 137 Iteration.break.Nested > [,]{(){ = ;;do{<< ; = ;do{if( == ){ break; } << ; = + 1;}while( < ); = - 1;}while( > );}} > Type: debug_output Hardness: 80 // OBJECTIVE IS TO SEE THAT STUDENTS UNDERSTAND THAT BREAK EXITS MOSTLY IMMEDIATELY ENCLOSING LOOP ONLY. // SO, ADDITION OF BREAK IN OUTER LOOP MAKES PROBLEMS HARDER WITHOUT ADDING TO THEIR LEARNABILITY // // // Nested for-loops, conditional breaks in both inner and outer loops // # 134 // Iteration.break.Nested // > // [,,,,,]{(){;;for( = ; < ; = + 1){<< ;if( >= ){ break; }for( = ; < ; = + 1){if( < ){ break; } << ;}}}} // > // Type: debug_output // Hardness: 80 // // // Nested while-loops, conditional breaks in both inner and outer loops // # 135 // Iteration.break.Nested // > // [,,,,,]{(){ = ;;while( < ){<< ;if( >= ){ break; } = ;while( < ){if( < ){ break; } << ; = + 1;} = + 1;}}} // > // Type: debug_output // Hardness: 80 // // // Nested do-while-loops, conditional breaks in both inner and outer loops // # 136 // Iteration.break.Nested // > // [,,,,,]{(){ = ;;do{<< ;if( >= ){ break; } = ;do{if( < ){ break; } << ; = + 1;}while( < ); = + 1;}while( < );}} // > // Type: debug_output // Hardness: 80 // ------------------------------------------------------------------------ // Iteration.break.break statement not inside a loop or switch statement 150 - 174 // unconditional break NOT in a loop, no loop involved # 150 Iteration.break.break statement not inside a loop or switch statement > {(){ = ; = - 1; << ; break; << + 1;}} > Type: debug_output Hardness: 30 // conditional break NOT in a loop, no loop involved # 151 Iteration.break.break statement not inside a loop or switch statement > {(){ = ; = + 1; << ; if( > 0 ) break; << + 1;}} > Type: debug_output Hardness: 30 // Conditional break before incrementing for-loop # 155 Iteration.break.break statement not inside a loop or switch statement > {(){ = ;if( <= ) break; for( = ; < ; = + ){<< ; }}} > Type: debug_output Hardness: 40 // Conditional break after incrementing while-loop # 156 Iteration.break.break statement not inside a loop or switch statement > {(){=;while( < ){<< ; = + ;} if( > ) break;}} > Type: debug_output Hardness: 40 // Conditional break after decrementing do-while-loop # 157 Iteration.break.break statement not inside a loop or switch statement > {(){=; do{ = - ; << ;}while( > ); if( <= ) break; }} > Type: debug_output Hardness: 40 // Pretest problem // Conditional break before decrementing while-loop # 158 Iteration.break.break statement not inside a loop or switch statement > {(){=;if( > ) break; while( > ){<< ; = - ;}}} > Type: debug_output Hardness: 40 // Conditional break after decrementing for-loop # 159 Iteration.break.break statement not inside a loop or switch statement > {(){;for( = ; > ; = - ){<< ; } if( < ) break;}} > Type: debug_output Hardness: 40 // Posttest problem // Conditional break before incrementing do-while-loop # 160 Iteration.break.break statement not inside a loop or switch statement > {(){=;if( <= ) break;do{ = + ; << ;}while( < );}} > Type: debug_output Hardness: 40 // ------------------------------------------------------------------------ // Iteration.continue.Correct 200 - 224 // Unconditional continue in for-loop # 200 Iteration.continue.Correct > {(){;for( = ; > ; = - 2){<< ; continue; << + 1;}}} > Type: debug_output Hardness: 30 // Unconditional continue in while-loop # 201 Iteration.continue.Correct > {(){=;while( < ){<< ; = + 2; continue; << ;}}} > Type: debug_output Hardness: 30 // Unconditional continue in do-while-loop # 202 Iteration.continue.Correct > {(){=;do{<< ; = - ; continue; << ;}while( > 0);}} > Type: debug_output Hardness: 30 // Conditional continue in for-loop, continue fires on first iteration # 205 Iteration.continue.Correct > {(){;for( = ; < ; = + 2){<< ; if( < ) continue; << + 1;}}} > Type: debug_output Hardness: 40 // Conditional continue in while-loop, continue fires on first iteration, # 206 Iteration.continue.Correct > {(){=;while( > ){ = - ; if( <= ) continue; << ;}}} > Type: debug_output Hardness: 40 // Conditional continue in do-while-loop, continue fires on first iteration, # 207 Iteration.continue.Correct > {(){=;do{ << ; = + 2; if( > ) continue; << ;}while( < );}} > Type: debug_output Hardness: 40 // Conditional continue in for-loop, continue fires on second iteration # 210 Iteration.continue.Correct > {(){;for( = ; > ; = - 2){<< ; if( < ) continue; << - 1;}}} > Type: debug_output Hardness: 50 // Pretest problem // Conditional continue in while-loop, continue fires on second iteration # 211 Iteration.continue.Correct > {(){=;while( < ){ << ; = + ; if( > ) continue; << + 1;}}} > Type: debug_output Hardness: 50 // Posttest problem // Conditional continue in do-while-loop, continue fires on second iteration # 212 Iteration.continue.Correct > {(){=;do{ << ; = - ; if( < ) continue; << - 1;}while( > );}} > Type: debug_output Hardness: 50 // NESTED LOOPS ARE TOO HARD TO LEARN CONTINUE CONCEPT AND DISTRACT FROM IT // // // Nested for-loops, conditional continue in inner loop dependent on inner loop variable // # 206 // Iteration.continue.Correct // > // [,,,,]{(){;;for( = ; < ; = + 1){<< ;for( = ; < ; = + 1){if( < ){ continue; } << ;}}}} // > // Type: debug_output // Hardness: 80 // // // Nested while-loops, conditional continue in inner loop dependent on inner loop variable // # 207 // Iteration.continue.Correct // > // [,,,,]{(){ = ;;while( < ){<< ; = ;while( < ){ = + 1;if( < ){ continue; } << ;} = + 1;}}} // > // Type: debug_output // Hardness: 80 // // // Nested do-while-loops, conditional continue in inner loop dependent on outer loop variable // # 208 // Iteration.continue.Correct // > // [,,,,]{(){ = ;;do{<< ; = ;do{ = + 1;if( < ){ continue; } << ;}while( < ); = + 1;}while( < );}} // > // Type: debug_output // Hardness: 80 // // // Nested for-loops, conditional continue in inner loop dependent on outer loop variable // # 209 // Iteration.continue.Correct // > // [,,,,]{(){;;for( = ; < ; = + 1){<< ;for( = ; < ; = + 1){if( >= ){ continue; } << ;}}}} // > // Type: debug_output // Hardness: 80 // // // Nested while-loops, conditional continue in outer loop // # 210 // Iteration.continue.Correct // > // [,,,,]{(){ = ;;while( < ){<< ; = + 1;if( >= ){ continue; } = ;while( < ){ << ; = + 1;}}}} // > // Type: debug_output // Hardness: 80 // // // Nested do-while-loops, conditional continue in outer loop // # 211 // Iteration.continue.Correct // > // [,,,,]{(){ = ;;do{<< ; = + 1;if( >= ){ continue; } = ;do{ << ; = + 1;}while( < );}while( < );}} // > // Type: debug_output // Hardness: 80 // ------------------------------------------------------------------------ // Iteration.continue.continue statement not inside a loop 225 - 249 # 225 Iteration.continue.continue statement not inside a loop > {(){ = ; = - 1; << ; continue; << + 1;}} > Type: debug_output Hardness: 30 // conditional continue NOT in a loop, no loop involved # 226 Iteration.continue.continue statement not inside a loop > {(){ = ; = + 1; << ; if( > 0 ) continue; << - 1;}} > Type: debug_output Hardness: 30 // Conditional continue after decrementing for-loop # 230 Iteration.continue.continue statement not inside a loop > {(){;for( = ; > ; = - ){<< ; } if( < ) continue;}} > Type: debug_output Hardness: 40 // Conditional continue before decrementing while-loop # 231 Iteration.continue.continue statement not inside a loop > {(){=;if( >= ) continue; while( > ){<< ; = - ;}}} > Type: debug_output Hardness: 40 // Conditional continue before incrementing do-while-loop # 232 Iteration.continue.continue statement not inside a loop > {(){=;if( < ) continue;do{ = + ; << ;}while( <=);}} > Type: debug_output Hardness: 40 // Conditional continue after incrementing while-loop # 233 Iteration.continue.continue statement not inside a loop > {(){=;while( < ){<< ; = + ;} if( >= ) continue;}} > Type: debug_output Hardness: 40 // Pretest problem // Conditional continue before incrementing for-loop # 234 Iteration.continue.continue statement not inside a loop > {(){ = ;if( <= ) continue; for( = ; < ; = + ){<< ; }}} > Type: debug_output Hardness: 40 // Posttest problem // Conditional continue after decrementing do-while-loop # 235 Iteration.continue.continue statement not inside a loop > {(){=; do{ = - ; << ;}while( > ); if( <= ) continue; }} > Type: debug_output Hardness: 40 // ------------------------------------------------------------------------ // Iteration.Infinite.Condition variable is not updated in the loop - 300 # 300 Iteration.Infinite.Condition variable is not updated in the loop > {(){=;iwhile( < ){<<;}}} > Type: debug_output Hardness: 40 # 301 Iteration.Infinite.Condition variable is not updated in the loop > {(){=;ido{<<;}while( >= );}} > Type: debug_output Hardness: 40 # 302 Iteration.Infinite.Condition variable is not updated in the loop > {(){;ifor(=; < ; ){<<;}}} > Type: debug_output Hardness: 40 // Pretest problem # 303 Iteration.Infinite.Condition variable is not updated in the loop > {(){=;iwhile( > ){<<;}}} > Type: debug_output Hardness: 40 // Posttest problem # 304 Iteration.Infinite.Condition variable is not updated in the loop > {(){=;ido{<<;}while( <= );}} > Type: debug_output Hardness: 40 # 305 Iteration.Infinite.Condition variable is not updated in the loop > {(){;ifor(=; > ; ){<<;}}} > Type: debug_output Hardness: 40 // ------------------------------------------------------------------------ // Iteration.Infinite.Condition variable is incorrectly updated in the loop - 325 // iwhile, ifor, ido, alternated // >, >=, <, <= alternated // update by 1 versus many - alternated # 325 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){=;iwhile( > ){ = + 1;<<;}}} > Type: debug_output Hardness: 40 # 326 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){;ifor(=; <= ; = - 1){<<;}}} > Type: debug_output Hardness: 40 # 327 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){=;ido{ = + ;<<;}while( > );}} > Type: debug_output Hardness: 40 # 328 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){;ifor(=; != ; = + 2){<<;}}} > Type: debug_output Hardness: 40 // Pretest problem # 329 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){=;iwhile( <= ){<<; = - ;}}} > Type: debug_output Hardness: 40 // Posttest problem # 330 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){;ifor(=; > ; = + ){<<;}}} > Type: debug_output Hardness: 40 # 331 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){=;ido{ = - 1;<<;}while( <= );}} > Type: debug_output Hardness: 40 # 332 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){;ifor(=; != ; = - 2){<<;}}} > Type: debug_output Hardness: 40 ///////// sides swapped in condition # 335 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){=;iwhile( >= ){<<; = - 1;}}} > Type: debug_output Hardness: 40 # 336 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){;ifor(=; < ; = + ){<<;}}} > Type: debug_output Hardness: 40 # 337 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){=;ido{ = - 1;<<;}while( >= );}} > Type: debug_output Hardness: 40 # 338 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){;ifor(=; != ; = + 10){<<;}}} > Type: debug_output Hardness: 40 # 339 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){=;iwhile( < ){ = + ;<<;}}} > Type: debug_output Hardness: 40 # 340 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){;ifor(=; >= ; = - 1){<<;}}} > Type: debug_output Hardness: 40 # 341 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){=;ido{<<; = + ;}while( < );}} > Type: debug_output Hardness: 40 # 342 Iteration.Infinite.Condition variable is incorrectly updated in the loop > {(){;ifor(=; != ; = - 10){<<;}}} > Type: debug_output Hardness: 40 //////// // USE THIS FOR TERMINAL VALUE CHANGED - CORRECT UPDATE, GREATER UPDATE OF TERMINAL VALUE // Multiple opposite changes // // This meets both incorrect update and change in terminal value, so commented out // //Condition - decreases, Boundary - increases // # 343 // Iteration.Infinite.Condition variable is incorrectly updated in the loop // > // {(){=;;ifor(=; < ; = - 1){<<; = + 1;<<;}}} // > // Type: debug_output // Hardness: 50 // // Terminal value is being modified in the correct direction, only that the increment // // is not properly synchronized with the decrement of loop variable. So, commented out // //Condition - increases, Boundary - decreases, Condition and Boundary pass each other // # 345 // Iteration.Infinite.Condition variable is incorrectly updated in the loop // > // {(){ = 1;;ifor( = 20; != ; = - 3){ = + 1;<<;<<;}}} // > // Type: debug_output // Hardness: 70 // // Does this work - NOT always an infinite loop // #346 // Iteration.Infinite.Condition variable is incorrectly updated in the loop // > // {(){=;;ifor(=; != ; = - 1, = + 1){<<;<<;}}} // > // Type: debug_output // Hardness: 50// FROM HERE // ------------------------------------------------------------------------ // Iteration.Infinite.Value against which condition variable is compared is also modified - 350 // Created one each of for, while, do-while for: // condition increase- boundary increase // condition decrease- boundary decrease // condition increase- boundary increase, but by more // and scrambled them together //Condition - increases, Boundary - increases # 350 Iteration.Infinite.Value against which condition variable is compared is also modified > {(){=;;ifor(=; <= ; = + ){<<; = + ;<<;}}} > Type: debug_output Hardness: 40 //Condition - decreasing, Boundary - decreasing # 351 Iteration.Infinite.Value against which condition variable is compared is also modified > {(){=;=;iwhile( >= ){ = - ; <<; = - ; <<;}}} > Type: debug_output Hardness: 40 //Condition - increases, Boundary - increases, Condition < Boundary, Boundary increases faster # 352 Iteration.Infinite.Value against which condition variable is compared is also modified > {(){=;=;ido{<<;<<; = + ; = + ; }while( != );}} > Type: debug_output Hardness: 50 //Condition - decreasing, Boundary - decreasing # 353 Iteration.Infinite.Value against which condition variable is compared is also modified > {(){=;;ifor(=; <= ; = - ){<<;<<; = - ;}}} > Type: debug_output Hardness: 40 //Condition - increases, Boundary - increases, Condition < Boundary, Boundary increases faster # 354 Iteration.Infinite.Value against which condition variable is compared is also modified > {(){=;=;iwhile( != ){ = + ; <<; = + ; <<;}}} > Type: debug_output Hardness: 50 //Condition - increases, Boundary - increases # 355 Iteration.Infinite.Value against which condition variable is compared is also modified > {(){=;=;ido{ = + ; <<; = + ; <<;}while( <= );}} > Type: debug_output Hardness: 40 //Condition - increases, Boundary - increases, Condition < Boundary, Boundary increases faster # 356 Iteration.Infinite.Value against which condition variable is compared is also modified > {(){=;;ifor(=; != ; = + ){<<;<<; = + ;}}} > Type: debug_output Hardness: 50 //Pretest problem //Condition - increases, Boundary - increases # 357 Iteration.Infinite.Value against which condition variable is compared is also modified > {(){=;=;iwhile( <= ){ = + ; = + ; <<;<<;}}} > Type: debug_output Hardness: 40 // Posttest problem //Condition - decreasing, Boundary - decreasing # 358 Iteration.Infinite.Value against which condition variable is compared is also modified > {(){=;=;ido{ = - ; <<; = - ;<<;}while( >= );}} > Type: debug_output Hardness: 40 //Condition - decreases, Boundary - increases, Condition > Boundary, Skip over each other # 360 Iteration.Infinite.Value against which condition variable is compared is also modified > {(){ = 1;;ifor( = 10; != ; = - 3, = + 1){<<;<<;}}} > Type: debug_output Hardness: 60 //Condition - decreases, Boundary - increases, Condition > Boundary, Skip over each other # 361 Iteration.Infinite.Value against which condition variable is compared is also modified > {(){ = 1; = 9;iwhile( != ){ = - 2; <<; = + 1;<<;}}} > Type: debug_output Hardness: 60 //Condition - decreases, Boundary - increases, Condition > Boundary, Skip over each other # 362 Iteration.Infinite.Value against which condition variable is compared is also modified > {(){ = 1; = 8;ido{<<;<<; = - 3; = + 2;}while( != );}} > Type: debug_output Hardness: 60 // // Same as 353 // // Multiple same-directional changes - dec/dec - same value // # 344 // Iteration.Infinite.Condition variable is incorrectly updated in the loop // > // {(){=;;ifor(=; != ; = - 1){<<; = - 1;<<;}}} // > // Type: debug_output // Hardness: 60 // ------------------------------------------------------------------------ // Iteration.Infinite.Assignment is used in condition - 375 # 375 Iteration.Infinite.Assignment is used in condition > {(){;ifor( = ; = ; = + ){<<;}}} > Type: debug_output Hardness: 40 # 376 Iteration.Infinite.Assignment is used in condition > {(){=;iwhile( = ){<<; = - ;}}} > Type: debug_output Hardness: 40 # 377 Iteration.Infinite.Assignment is used in condition > {(){=;ido{<<; = + ;}while( = );}} > Type: debug_output Hardness: 40 # 378 Iteration.Infinite.Assignment is used in condition > {(){;ifor(=; = 1; = - ){<<;}}} > Type: debug_output Hardness: 40 # 379 Iteration.Infinite.Assignment is used in condition > {(){=;iwhile( = ){ = + ;<<;}}} > Type: debug_output Hardness: 40 # 380 Iteration.Infinite.Assignment is used in condition > {(){=;ido{ = - ;<<;}while( = 1);}} > Type: debug_output Hardness: 40 // Pretest problem # 385 Iteration.Infinite.Assignment is used in condition > {(){;ifor(=; = ; = + ){<<;}}} > Type: debug_output Hardness: 40 // Posttest problem # 386 Iteration.Infinite.Assignment is used in condition > {(){=;iwhile( = ){<<; = + ;}}} > Type: debug_output Hardness: 40 # 387 Iteration.Infinite.Assignment is used in condition > {(){=;ido{ = + ;<<;}while( = );}} > Type: debug_output Hardness: 40 // ------------------------------------------------------------------------ // Iteration.Infinite.Empty condition in for loop // THIS APPLIES ONLY TO FOR LOOPS IN C++/JAVA/C# - # 400 Iteration.Infinite.Empty condition in for loop > {(){;ifor(=; ; = + ){<<;}}} > Type: debug_output Hardness: 40 # 401 Iteration.Infinite.Empty condition in for loop > {(){;ifor(=; ; = - ){<<;}}} > Type: debug_output Hardness: 40 # 402 Iteration.Infinite.Empty condition in for loop > {(){;ifor(=; ; = / 2){<<;}}} > Type: debug_output Hardness: 45 // ------------------------------------------------------------------------ // Iteration.Logic.Pretest.Condition.Empty // THE FOLLOWING ARE SYNTAX ERRORS IN C++/JAVA/C# # 425 Iteration.Logic.Pretest.Condition.Empty > {(){=;while(){ = - ;<<;}}} > Type: debug_output Hardness: 40 # 426 Iteration.Logic.Pretest.Condition.Empty > {(){=;while(){<<; = + ;}}} > Type: debug_output Hardness: 40 # 427 Iteration.Logic.Pretest.Condition.Empty > {(){=;while(){<<; = * 2;}}} > Type: debug_output Hardness: 45 // ------------------------------------------------------------------------ // Iteration.Logic.Posttest.Condition.Empty // THE FOLLOWING ARE SYNTAX ERRORS IN C++/JAVA/C# # 450 Iteration.Logic.Posttest.Condition.Empty > {(){=;do{<<; = + ;}while();}} > Type: debug_output Hardness: 40 # 451 Iteration.Logic.Posttest.Condition.Empty > {(){=;do{ = - ;<<;}while();}} > Type: debug_output Hardness: 40 # 452 Iteration.Logic.Posttest.Condition.Empty > {(){=;do{ = + ;<< ;}while();}} > Type: debug_output Hardness: 45 // ------------------------------------------------------------------------ // Iteration.Infinite.Condition is a constant - either always true or always false - 475-499 added 4/6/10 Raph E Walde // Infinite loops for C++ and compiler error for Java and C# // for-loop, increase loop variable, output loop variable # 475 Iteration.Infinite.Condition is a constant - either always true or always false > {(){;ifor(=;; = + ){<<;}}} > Type: debug_output Hardness: 40 // while-loop, decrease loop variable, output loop variable expression # 476 Iteration.Infinite.Condition is a constant - either always true or always false > {(){=;iwhile(){ = - ;<< + ;}}} > Type: debug_output Hardness: 45 // do-while-loop, increase loop variable, output loop variable expression # 477 Iteration.Infinite.Condition is a constant - either always true or always false > {(){=;ido{ = + ;<< * 2;}while();}} > Type: debug_output Hardness: 45 // for-loop, decrease loop variable, output loop variable expression # 478 Iteration.Infinite.Condition is a constant - either always true or always false > {() {;ifor(=;; = - ){<< + ;}}} > Type: debug_output Hardness: 45 // while-loop, increase loop variable, output loop variable # 479 Iteration.Infinite.Condition is a constant - either always true or always false > {(){=;iwhile(){<<; = + ;}}} > Type: debug_output Hardness: 40 // do-while-loop, decrease loop variable, output loop variable # 480 Iteration.Infinite.Condition is a constant - either always true or always false > {(){=;ido{ = - ;<<;}while();}} > Type: debug_output Hardness: 40 // Condition is constant expression // Pretest problem // for-loop, increase loop variable, output loop variable # 485 Iteration.Infinite.Condition is a constant - either always true or always false > {(){;ifor(=; + ; = + ){<<;}}} > Type: debug_output Hardness: 50 // Posttest problem // while-loop, decrease loop variable, output loop variable expression # 486 Iteration.Infinite.Condition is a constant - either always true or always false > {(){=;iwhile( - ){ = - ;<< + ;}}} > Type: debug_output Hardness: 55 // do-while-loop, increase loop variable, output loop variable expression # 487 Iteration.Infinite.Condition is a constant - either always true or always false > {(){=;ido{ = + ;<< * 2;}while( * );}} > Type: debug_output Hardness: 55 // for-loop, decrease loop variable, output loop variable expression # 488 Iteration.Infinite.Condition is a constant - either always true or always false > {() {;ifor(=; / ; = - ){<< + ;}}} > Type: debug_output Hardness: 55 // while-loop, increase loop variable, output loop variable # 489 Iteration.Infinite.Condition is a constant - either always true or always false > {(){=;iwhile( % ){<<; = + ;}}} > Type: debug_output Hardness: 50 // do-while-loop, decrease loop variable, output loop variable # 490 Iteration.Infinite.Condition is a constant - either always true or always false > {(){=;ido{ = - ;<<;}while( / );}} > Type: debug_output Hardness: 50 // ------------------------------------------------------------------------ // Iteration.Mixed.Multiple Dependent - 500-524 // Dependence based on start/final/update value interleaved for the 3 types of loops and combinations of inc/dec // for-loop followed by while-loop, last value of first loop variable is first value of second loop variable, loop variables are output in loops - for/while, dec/inc # 500 Iteration.Mixed.Multiple Dependent > [,,]{(){;;for( = ; > ; = - 1){<< ;} = ;while( < ){<< ; = + 1;}}} > Type: debug_output Hardness: 40 // for-loop followed by do-while-loop, first loop variable is in termination condition for second loop, loop variable expressions are output - for/do, inc/inc # 501 Iteration.Mixed.Multiple Dependent > [,,]{(){;;for( = ; < ; = + 1 ){<< +1;} = ;do{<< ; = + 1;}while( < );}} > Type: debug_output Hardness: 40 // dependence on update value - for/while, dec-dec # 502 Iteration.Mixed.Multiple Dependent > [,,]{(){;for( = ; > ; = - 1){<< ;}; = ;while( >= ){<< ; = - ;}}} > Type: debug_output Hardness: 40 // while-loop followed by do-while-loop, last value of first loop variable is first value of second loop variable, loop variables are output in loops - while/do, inc/inc # 503 Iteration.Mixed.Multiple Dependent > [,,]{(){=;;while( < ){ = + 1;<< ;} = ;do{<< ; = + 1;}while( < );}} > Type: debug_output Hardness: 40 // while-loop followed by for-loop, first loop variable is in termination condition for second loop, loop variable expressions are output - while/for, inc/dec # 504 Iteration.Mixed.Multiple Dependent > [,,]{(){=;;while( < ){ = + 1;<< ;}for( = ; > ; = - 1){<< - 1;}}} > Type: debug_output Hardness: 40 // dependence on update value - do/while, inc-dec # 505 Iteration.Mixed.Multiple Dependent > [,,,]{(){=;do{ << ; = + 1;}while( < );; = ;while( > ){<< ; = - ;}}} > Type: debug_output Hardness: 40 // Pretest problem // do-while-loop followed by for-loop, last value of first loop variable is first value of second loop variable, loop variables are output in loops - do/for, dec/inc # 506 Iteration.Mixed.Multiple Dependent > [,,]{(){=;;do{<< ; = - 1;}while( > );for( = ; < ; = + 1){<< ;}}} > Type: debug_output Hardness: 40 // Posttest problem // do-while-loop followed by while-loop, first loop variable is in termination condition for second loop, loop variable expressions are output - do/while, inc/inc # 507 Iteration.Mixed.Multiple Dependent > [,,]{(){=;;do{ = + 2; << ;}while( < ); = ;while( < ){<< ; = + 1;}}} > Type: debug_output Hardness: 40 // dependence on update value - do/for, dec-dec # 508 Iteration.Mixed.Multiple Dependent > [,,]{(){=;do{ = - 1;<< ;}while( > );;for( = ; > ; = - ){<< ;}}} > Type: debug_output Hardness: 40 // // COMMENTED OUT SINCE THESE ARE NOT DEPENDENT - ITERATIONS OF SECOND LOOP NOT DETERMINED BY FIRST LOOP // // for-loop followed by while-loop, first loop variable is in conditional expression in second loop, loop variable expressions are output - dec/inc // # 506 // Iteration.Mixed.Multiple Dependent // > // [,,,]{(){;;for( = ; > ; = - 1){<< ;} = ;while( < ){if( < )<< ;else << ; = + 2;}}} // > // Type: debug_output // Hardness: 40 // // // while-loop followed by do-while-loop, first loop variable is in conditional expression in second loop, loop variable expressions are output // # 507 // Iteration.Mixed.Multiple Dependent // > // [,,,]{(){=;;while( < ){<< - ; = + 1;} = ;do{if( <= )<< - ;else << - ; = + 2;}while( < );}} // > // Type: debug_output // Hardness: 40 // // // do-while-loop followed by for-loop, first loop variable is in conditional expression in second loop, loop variable expressions are output // # 508 // Iteration.Mixed.Multiple Dependent // > // [,,,,]{(){=;;do{ << ; = +1;}while( < );for( = ; < ; = + 1){if( < )<< ;else << ;}}} // > // Type: debug_output // Hardness: 40 // for-loop followed by do-while-loop followed by while-loop, earlier loop variables used in various ways in later loops # 510 Iteration.Mixed.Multiple Dependent > [,,,]{(){;;;for( = ; < ; = + 1){<< ;} = ;do{<< ; = + 1;}while( < ); = ;while( < ){<< ; = + 2;}}} > Type: debug_output Hardness: 60 // while-loop followed by for-loop followed by do-while-loop, earlier loop variables used in various ways in later loops # 511 Iteration.Mixed.Multiple Dependent > [,,,,]{(){=;;;while( < ){ = + 1; << ;}for( = ; < ; = + 2){<< + 1;} = ;do{<< - 1; = - 2;}while( > );}} > Type: debug_output Hardness: 60 // do-while-loop followed by while-loop followed by for-loop, earlier loop variables used in various ways in later loops # 512 Iteration.Mixed.Multiple Dependent > [,,]{(){=;;;do{ = + 2;<< ;}while( < ); = ;while( > ){ = - 1;<< ;}for( = ; < ; = + 1){<< ;}}} > Type: debug_output Hardness: 60 // ------------------------------------------------------------------------ // Iteration.Mixed.Nested Dependent - 550 - 574 // Dependence on init/final/update value - interleaved with 6 combinations of the 3 loops and 4 combinations of inc/dec // For-loop containing a while-loop, first loop variable is initial value for second loop variable, loop variables are output - for/while, inc/inc # 550 Iteration.Mixed.Nested Dependent > [,,]{(){;;for( = ; < ; = + 1){<< ; = ;while( < ){<< ; = + 1;}}}} > Type: debug_output Hardness: 80 // for-loop containing a do-while-loop, first loop variable is in exit expression for second loop, loop variables are output - for/do, inc/inc # 551 Iteration.Mixed.Nested Dependent > [,,]{(){;;for( = ; < ; = + 1){ = ;do{<< ; = + 1;}while( < );<< ;}}} > Type: debug_output Hardness: 80 // first loop variable is update value for second loop variable, loop variables are output - while/do, dec/inc # 552 Iteration.Mixed.Nested Dependent > [,,]{(){ = ;;while( > ){ = ;do{<< ; = + ;}while( <= );<< ; = - 1;}}} > Type: debug_output Hardness: 80 // while-loop containing a do-while-loop, first loop variable is initial value for second loop variable, loop variables are output - while/do, inc/inc # 553 Iteration.Mixed.Nested Dependent > [,]{(){ = ;;while( < ){ = ;do{<< ; = + 1;}while( < );<< ; = + 1;}}} > Type: debug_output Hardness: 80 // while-loop containing a for-loop, first loop variable is in exit expression for second loop, loop variables are output - while/for, dec/dec # 554 Iteration.Mixed.Nested Dependent > [,]{(){ = ;;while( > ){<< ;for( = ; > ; = - 1){<< ;} = - 1;}}} > Type: debug_output Hardness: 80 // first loop variable is update for second loop, loop variables are output - for/do, inc/dec # 555 Iteration.Mixed.Nested Dependent > [,,]{(){;;for( = ; < ; = + 1){ = ;do{<< ; = - ;}while( > );<< ;}}} > Type: debug_output Hardness: 80 // Pretest problem // do-while-loop containing a for-loop, first loop variable is initial value for second loop variable, loop variables are output - do/for, dec/inc # 556 Iteration.Mixed.Nested Dependent > [,,]{(){ = ;;do{<< ;for( = ; < ; = + 1){<< ;} = - 1;}while( > );}} > Type: debug_output Hardness: 80 // Posttest problem // do-while-loop containing a while-loop, first loop variable is in exit expression for second loop, loop variables are output - do/while, inc/dec # 557 Iteration.Mixed.Nested Dependent > [,,]{(){ = ;;do{ = ;while( > ){<< ; = - 1;}<< ; = + 1;}while( < );}} > Type: debug_output Hardness: 80 // first loop variable is update for second loop, loop variables are output - while/for, dec/dec # 558 Iteration.Mixed.Nested Dependent > [,,]{(){ = ;;while( > ){<< ;for( = ; >= ; = - ){<< ;} = - 1;}}} > Type: debug_output Hardness: 80 // WHEN DEPENDENT, NUMBER OF ITERATIONS OF NESTED LOOP DETERMINED BY VARIABLE FROM OUTER LOOP. // THAT IS NOT THE CASE IN THESE EXAMPLES, SO COMMENTED OUT. // // For-loop containing a while-loop, first loop variable is in an expression output inside second loop - for/while, inc/inc // # 556 // Iteration.Mixed.Nested Dependent // > // [,,,]{(){;;for( = ; < ; = + 1){ = ;while( < ){<< + ; = + 1;}}}} // > // Type: debug_output // Hardness: 80 // // // while-loop containing a do-while-loop, first loop variable is in an expression output inside second loop - while/do, inc/dec // # 557 // Iteration.Mixed.Nested Dependent // > // [,,,]{(){ = ;;while( < ){ = ;do{<< - ; = + 1;}while( < ); = + 1;}}} // > // Type: debug_output // Hardness: 80 // // // do-while-loop containing a for-loop, first loop variable is in an expression output inside second loop - do/for, dec/inc // # 558 // Iteration.Mixed.Nested Dependent // > // [,,,,]{(){ = ;;do{for( = ; < ; = + 1){<< + + ;} = - 1;}while( > );}} // > // Type: debug_output // Hardness: 80 // // // // // for-loop containing a do-while-loop, both loop variables are in an if-else-expression inside second loop - for/do, inc/inc // # 559 // Iteration.Mixed.Nested Dependent // > // [,,]{(){;;for( = ; < ; = + 1){ = ;do{if( <= )<< ;else << ; = + 1;}while( < );}}} // > // Type: debug_output // Hardness: 80 // // // while-loop containing a for-loop, both loop variables are in an if-else-expression inside second loop - while/for, inc/inc // # 560 // Iteration.Mixed.Nested Dependent // > // [,,,]{(){ = ;;while( < ){for( = ; < ; = + 1){if( > )<< ;else << ;} = + 1;}}} // > // Type: debug_output // Hardness: 80 // // // do-while-loop containing a while-loop, both loop variables are in an if-else-expression inside second loop - do/while, inc/dec // # 561 // Iteration.Mixed.Nested Dependent // > // [,,,]{(){ = ;;do{ = ;while( > ){if( < )<< ;else << + ; = - 1;} = + 1;}while( < );}} // > // Type: debug_output // Hardness: 80 // ------------------------------------------------------------------------ // Iteration.Accumulator 600 - 624 // Count the iterations in a for-loop, output count after loop # 600 Iteration.Accumulator > [,]{(){; = 0;for( = ; > ; = - 1){=+1;}<< ;}} > Type: debug_output Hardness: 30 // Sum the loop variable in a while-loop, output sum after loop # 601 Iteration.Accumulator > [,]{(){=; = 0;while( < ){ = + ; = + 1;}<< ;}} > Type: debug_output Hardness: 40 // Product of the loop variable in a do-while-loop, output product after loop # 602 Iteration.Accumulator > [,]{(){=; = 1;do{ = * ; = + 1; }while( < );<< ;}} > Type: debug_output Hardness: 40 // Finding the largest number in a series in a for-loop, output number after loop # 603 Iteration.Accumulator > [,,]{(){; = 0;for( = ; < ; = + 1){if( < ){=;}}<< ;}} > Type: debug_output Hardness: 40 // Finding the smallest number in a series in a while-loop, output number after loop # 604 Iteration.Accumulator > [,]{(){=; = 10;while( > ){if( > ){ = ;} = - 1;}<< ;}} > Type: debug_output Hardness: 40 // Finding number of numbers over 5 in a series in a do-while-loop, output number after loop # 605 Iteration.Accumulator > [,]{(){=; = 0;do{ if( >= 5){ = + 1;} = - 2;}while( > );<< ;}} > Type: debug_output Hardness: 40 // Double a number as many times as the iterations of a loop, output result after loop # 606 Iteration.Accumulator > [,]{(){; = 1;for( = ; > ; = - 2){ = * 2;}<< ;}} > Type: debug_output Hardness: 40 // Posttest problem // Subtract from accumulator as many times as the iterations of a loop, output result after loop # 607 Iteration.Accumulator > [,,]{(){=; = 10;while( < ){ = - ; = + ;}<< ;}} > Type: debug_output Hardness: 40 // Pretest problem // Multiplying accumulator by 10 as many times as the iteration of the do-while-loop, output result after loop # 608 Iteration.Accumulator > [,,]{(){=; = 1;do{ = * 10; = - ;}while( > );<< ;}} > Type: debug_output Hardness: 40 // NESTED LOOPS WILL INTERFERE WITH TESTING THE CONCEPT OF ACCUMULATOR VARIABLES // // Summing loop variables in nested for-loops, output sum after loops // # 609 // Iteration.Accumulator // > // [,,,]{(){;; = 0;for( = ; < ; = + 1){for( = ; < ; = + 1){=++;}}<< ;}} // > // Type: debug_output // Hardness: 80 // // // Summing loop variables in nested while-loops, output sum after loops // # 610 // Iteration.Accumulator // > // [,,,]{(){ = ;; = 0;while( < ){=+; = ;while( < ){=+;=+1;}=+1;}<< ;}} // > // Type: debug_output // Hardness: 80 // // // Summing the difference of the two loop variables in nested do-while-loops, output sum after loops // # 611 // Iteration.Accumulator // > // [,,,]{(){ = ;; = 0;do{<< ; = ;do{ = + - ; = + 1;}while( < ); = - 1;}while( > );<< ;}} // > // Type: debug_output // Hardness: 80 // -------------------------------------------------------------------------- // Templates here are for demonstration purposes // Included at the end so that regular practice does not pick up these templates // How to identify semantic error # 90 Demonstration > {(){;<<;}} > Type: debug_output Hardness: 10 // How to enter 2 outputs # 91 Demonstration > [,]{(){=;<<;=;<<;}} > Type: debug_output Hardness: 10 // How to enter no output # 92 Demonstration > {(){=9;; = 5; = + ; = + ;}} > Type: debug_output Hardness: 10 // // USED TO CREATE HELP FILES - MINIMIZE VARIABLE NAME CHOICE BEFORE RUNNING THIS // # 999 // Iteration.Accumulator // > // {(){; = 5;<< ;<< ; = 9;<< - ;}} // > // Type: debug_output // Hardness: 10 // --------------------------------------------------------------------------