// BACKED UP BEFORE INCORPORATING WALDE'S TEMPLATES // This is the master plan for the advanced topics in loops // break // Single // Nested // Illegal // continue // Correct // Illegal // Infinite // No update // Incorrect update // Moving terminal value // Assignment in condition // ... // Mixed // Multiple Dependent // Nested Dependent // Accumulator // Equivalent loops ? // // // ---------------------------------------------------- // 100 // Iteration.break.Single - 100 // Iteration.break.Nested - 125 // Iteration.break.Illegal - 150 // // Iteration.continue.Correct - 200 // Iteration.continue.Illegal - 225 // // Iteration.Infinite.No update statement in the loop - 300 // Iteration.Infinite.Incorrect update of loop variable - 325 // Iteration.Infinite.Terminal value modified in the loop - 350 // Iteration.Infinite.Assignment used in condition instead of comparison - 375 // // Iteration.Mixed.Multiple Dependent - 500 // Iteration.Mixed.Nested Dependent - 550 // // Iteration.Accumulator - 600 // // ------------------------------------------------------------------------ // Iteration.break.Single ************************************ 100 // Unconditional break works perfectly # 100 Iteration.break.Single > {(){;for( = ; > ; = - 1){<< ; break;}}} > Type: output Hardness: 40 // Conditional break, fires on first iteration // Works fine. Explanation interjects "If statement is exited" but otherwise, great # 101 Iteration.break.Single > {(){;for( = ; > ; = - 1){<< ; if( > 0 ) break;}}} > Type: output Hardness: 40 // Conditional break, fires on first iteration, additional statements after break - pose no problem // Works fine. Explanation interjects "If statement is exited" but otherwise, great # 102 Iteration.break.Single > {(){;for( = ; > ; = - 1){<< ; if( > 0 ) break; << + 1;}}} > Type: output Hardness: 40 // Conditional break, fires on first iteration, additional statements after break in if - works fine // Works fine. Explanation interjects "If statement is exited" but otherwise, great # 103 Iteration.break.Single > {(){;for( = ; > ; = - 1){<< ; if( > 0 ){ break; << 2;} << + 1;}}} > Type: output Hardness: 40 // Conditional break, does not fire on first iteration - works fine # 104 Iteration.break.Single > {(){;for( = ; > ; = - 1){<< ; if( == 2 ) break; << + 1;}}} > Type: output Hardness: 40 // ------------------------------------------------------------------------ // Iteration.break.Nested ************************************ 125 // Nested loops, breaking out of inner loop only - still works fine! # 125 Iteration.break.Nested > {(){;;for( = ; <= ; = + 1){<<;for( = ; <= ; = + 1){<<; if( == 3 ){ break; } }}}} > Type: output Hardness: 80 // ------------------------------------------------------------------------ // Iteration.break.Illegal ************************************ 150 // break and continue NOT in a loop # 150 Iteration.break.Illegal > {(){ = ; = - 1; << ; break; << + 1;}} > Type: debug Hardness: 40 // break and continue NOT in a loop # 151 Iteration.break.Illegal > {(){ = ; = + 1; << ; if( > 0 ) break; << + 1;}} > Type: debug Hardness: 40 // ------------------------------------------------------------------------ // Iteration.continue.Correct ********************************* 200 // Unconditional continue works perfectly # 825 Iteration.continue.Correct > {(){;for( = ; > ; = - 1){<< ; continue; << + 1;}}} > Type: output Hardness: 40 # 826 Iteration.continue.Correct > {(){;for( = ; > ; = - 1){continue; << + 1;}}} > Type: output Hardness: 40 // Conditional continue, fires on first iteration // Works fine. Explanation interjects "If statement is exited" but otherwise, great # 827 Iteration.continue.Correct > {(){;for( = ; > ; = - 1){<< ; if( > 0 ) continue; << + 1;}}} > Type: output Hardness: 40 // Works fine. Explanation interjects "If statement is exited" but otherwise, great # 828 Iteration.continue.Correct > {(){;for( = ; > ; = - 1){<< ; if( == ) continue; << + 1;}}} > Type: output Hardness: 50 // Conditional continue, fires on first iteration, additional statements after continue in if - works fine // Works fine. Explanation interjects "If statement is exited" but otherwise, great # 829 Iteration.continue.Correct > {(){;for( = ; > ; = - 1){ if( > 0 ){<< ; continue; << 2;} << + 1;}}} > Type: output Hardness: 40 // Nested loops, continueing out of inner loop only - still works fine! # 830 Iteration.continue.Correct > {(){;;for( = ; <= ; = + 1){<<;for( = ; <= ; = + 1){if( == 3 ){ continue; }<<; }}}} > Type: output Hardness: 80 // ------------------------------------------------------------------------ // Iteration.continue.Illegal ************************************ 225 # 225 Iteration.continue.Illegal > {(){ = ; = - 1; << ; continue; << + 1;}} > Type: debug Hardness: 40 // ------------------------------------------------------------------------ // Iteration.Infinite.No update statement in the loop - 300 // DONE # 300 Iteration.Infinite.No update statement in the loop ? > {(){=;iwhile( < ){<<;}}} > Type: debug_output Hardness: 100 # 301 Iteration.Infinite.No update statement in the loop ? > {(){=;ido{<<;}while( >= );}} > Type: debug_output Hardness: 100 # 302 Iteration.Infinite.No update statement in the loop ? > {(){ifor(=; < ; ){<<;}}} > Type: debug_output Hardness: 100 # 303 Iteration.Infinite.No update statement in the loop ? > {(){=;iwhile( > ){<<;}}} > Type: debug_output Hardness: 100 # 304 Iteration.Infinite.No update statement in the loop ? > {(){=;ido{<<;}while( <= );}} > Type: debug_output Hardness: 100 # 305 Iteration.Infinite.No update statement in the loop ? > {(){ifor(=; > ; ){<<;}}} > Type: debug_output Hardness: 100 // ------------------------------------------------------------------------ // Iteration.Infinite.Incorrect update of loop variable - 325 // iwhile, ifor, ido, alternated // >, >=, <, <= alternated // update by 1 versus many - alternated # 325 Iteration.Infinite.Incorrect update of loop variable ? > {(){=;iwhile( > ){ = + 1;<<;}}} > Type: debug Hardness: 100 # 326 Iteration.Infinite.Incorrect update of loop variable ? > {(){ifor(=; <= ; = - 1){<<;}}} > Type: debug Hardness: 100 # 327 Iteration.Infinite.Incorrect update of loop variable ? > {(){=;ido{ = + ;<<;}while( > );}} > Type: debug Hardness: 100 # 328 Iteration.Infinite.Incorrect update of loop variable ? > {(){;ifor(=; != ; = + 2){<<;}}} > Type: debug Hardness: 100 # 329 Iteration.Infinite.Incorrect update of loop variable ? > {(){=;iwhile( <= ){<<; = - ;}}} > Type: debug Hardness: 100 # 330 Iteration.Infinite.Incorrect update of loop variable ? > {(){ifor(=; > ; = + ){<<;}}} > Type: debug Hardness: 100 # 331 Iteration.Infinite.Incorrect update of loop variable ? > {(){=;ido{ = - 1;<<;}while( <= );}} > Type: debug Hardness: 100 # 332 Iteration.Infinite.Incorrect update of loop variable ? > {(){;ifor(=; != ; = - 2){<<;}}} > Type: debug Hardness: 100 ///////// sides swapped in condition # 335 Iteration.Infinite.Incorrect update of loop variable ? > {(){=;iwhile( >= ){<<; = - 1;}}} > Type: debug Hardness: 100 # 336 Iteration.Infinite.Incorrect update of loop variable ? > {(){ifor(=; < ; = + ){<<;}}} > Type: debug Hardness: 100 # 337 Iteration.Infinite.Incorrect update of loop variable ? > {(){=;ido{ = - 1;<<;}while( >= );}} > Type: debug Hardness: 100 # 338 Iteration.Infinite.Incorrect update of loop variable ? > {(){;ifor(=; != ; = + 10){<<;}}} > Type: debug Hardness: 100 # 339 Iteration.Infinite.Incorrect update of loop variable ? > {(){=;iwhile( < ){ = + ;<<;}}} > Type: debug Hardness: 100 # 340 Iteration.Infinite.Incorrect update of loop variable ? > {(){ifor(=; >= ; = - 1){<<;}}} > Type: debug Hardness: 100 # 341 Iteration.Infinite.Incorrect update of loop variable ? > {(){=;ido{<<; = + ;}while( < );}} > Type: debug Hardness: 100 # 342 Iteration.Infinite.Incorrect update of loop variable ? > {(){;ifor(=; != ; = - 10){<<;}}} > Type: debug Hardness: 100 // ------------------------------------------------------------------------ // Iteration.Infinite.Terminal value modified in the loop - 350 //Condition - increases, Boundary - increases #415 Iteration.Infinite.Terminal value modified in the loop ? > {(){=;ifor(=; <= ; = + 1, = + 1){<<;<<;}}} > Type: debug Hardness: 100 //Condition - decreasing, Boundary - decreasing #419 Iteration.Infinite.Terminal value modified in the loop ? > {(){=;ifor(=; >= ; = - 1, = - 1){<<;<<;}}} > Type: debug Hardness: 100 //Condition - increases, Boundary - increases, Condition < Boundary, Boundary increases faster #441 Iteration.Infinite.Terminal value modified in the loop ? > {(){=;ifor(=; != ; = + 1, = + 2){<<;<<;}}} > Type: debug Hardness: 100 //Condition - increases, Boundary - increases, Condition > Boundary, Condition increases at same rate #443 Iteration.Infinite.Terminal value modified in the loop ? > {(){=;ifor(=; != ; = + 3, = + 3){<<;<<;}}} > Type: debug Hardness: 100 //Condition - decreases, Boundary - increases, Condition > Boundary, Skip over each other #445 Iteration.Infinite.Terminal value modified in the loop ? > {(){=;ifor(=; != ; = - 3, = + 1){<<;<<;}}} > Type: debug Hardness: 100 //////// // USE THIS FOR TERMINAL VALUE CHANGED - CORRECT UPDATE, GREATER UPDATE OF TERMINAL VALUE // Multiple opposite changes //Condition - decreases, Boundary - increases #413 Iteration.Infinite.Incorrect update of loop variable ? > {(){=;ifor(=; < ; = - 1, = + 1){<<;<<;}}} > Type: debug Hardness: 100 // Multiple same-directional changes #436 Iteration.Infinite.Incorrect update of loop variable ? > {(){=;ifor(=; != ; = - 1, = - 1){<<;<<;}}} > Type: debug Hardness: 100 //Condition - increases, Boundary - decreases, Condition and Boundary pass each other #432 Iteration.Infinite.Incorrect update of loop variable ? > {(){=;ifor(=; != ; = + 1, = - 3){<<;<<;}}} > Type: debug Hardness: 100 // Does this work? #433 Iteration.Infinite.Incorrect update of loop variable ? > {(){=;ifor(=; != ; = - 1, = + 1){<<;<<;}}} > Type: debug Hardness: 100 // ------------------------------------------------------------------------ // Iteration.Infinite.Assignment is used in condition instead of comparison - 375 #447 Iteration.Infinite.Assignment is used in condition instead of comparison ? > {(){=;ifor(=; = 1; = + 1){<<;<<;}}} > Type: debug Hardness: 100 #509 Iteration.Infinite.Assignment is used in condition instead of comparison ? > {(){=;iwhile( = 5){<<;}}} > Type: debug Hardness: 100 #530 Iteration.Infinite.Assignment is used in condition instead of comparison ? > {(){=;iwhile( = 3){<<; = + 2;}}} > Type: debug Hardness: 100 #609 Iteration.Infinite.Assignment is used in condition instead of comparison > {(){=;ido{<<;}while( = 2);}} > Type: debug Hardness: 100 #625 Iteration.Infinite.Assignment is used in condition instead of comparison ? > {(){=;ido{ = + 2;<<;}while( = 1);}} > Type: debug Hardness: 100 // ------------------------------------------------------------------------ // Iteration.Infinite.Empty condition is treated as always true // ??? //Empty Condition ***************************** #449 Iteration.Infinite.Empty condition is treated as always true ? > {(){ifor(=; ; = + 1){<<;}}} > Type: debug Hardness: 100 #402 Iteration.Infinite.Empty condition is treated as always true ? > {(){ifor(=; ; = + 1){<<;}}} > Type: debug Hardness: 100 #404 Iteration.Infinite.Empty condition is treated as always true ? > {(){ifor(=; ; = - 1){<<;}}} > Type: debug Hardness: 100 #406 Iteration.Infinite.Empty condition is treated as always true ? > {(){ifor(=; ; = + 5){<<;}}} > Type: debug Hardness: 100 #408 Iteration.Infinite.Empty condition is treated as always true ? > {(){ifor(=; ; = - 3){<<;}}} > Type: debug Hardness: 100 #502 Iteration.Infinite.Empty condition is treated as always true ? > {(){=;iwhile(){<<; = + 1;}}} > Type: debug Hardness: 100 #504 Iteration.Infinite.Empty condition is treated as always true ? > {(){=;iwhile(){<<; = - 1;}}} > Type: debug Hardness: 100 #506 Iteration.Infinite.Empty condition is treated as always true ? > {(){=;iwhile(){<<; = + 5;}}} > Type: debug Hardness: 100 #508 Iteration.Infinite.Empty condition is treated as always true ? > {(){=;iwhile(){<<; = - 4;}}} > Type: debug Hardness: 100 //Empty Condition *********************** #532 Iteration.Infinite.Empty condition is treated as always true ? > {(){=;iwhile(){<<; = - 2;}}} > Type: debug Hardness: 100 #602 Iteration.Infinite.Empty condition is treated as always true ? > {(){=;ido{<<; = + 1;}while();}} > Type: debug Hardness: 100 #604 Iteration.Infinite.Empty condition is treated as always true ? > {(){=;ido{<<; = - 1;}while();}} > Type: debug Hardness: 100 #606 Iteration.Infinite.Empty condition is treated as always true > {(){=;ido{<<; = + 5;}while();}} > Type: debug Hardness: 100 #608 Iteration.Infinite.Empty condition is treated as always true > {(){=;ido{<<; = - 2;}while();}} > Type: debug Hardness: 100 #627 Iteration.Infinite.Empty condition is treated as always true ? > {(){=;ido{<<; = - 1;}while();}} > Type: debug Hardness: 100 #626 Iteration.Infinite.Empty condition is treated as always true ? > {(){=;ido{ = + 1;<<;}while(1);}} > Type: debug Hardness: 100 // ------------------------------------------------------------------------ // Iteration.Mixed.Multiple Dependent - 500 // ------------------------------------------------------------------------ // Iteration.Mixed.Nested Dependent - 550 // ------------------------------------------------------------------------ // Iteration.Accumulator - 600 // such as // sum = 0; // for( index = 0; index < size; index++ ) // { // sum = sum + index; // } // cout << sum; // How about min, max? // -------------------------------------------------------------------------- // Templates here are for demonstration purposes // Included at the end so that regular practice does not pick up these templates // How to enter 2 outputs # 90 Demonstration > {(){=;<<;=;<<;<< - ;}} > Type: output Hardness: 10 // How to enter multiple outputs from the same line # 91 Demonstration > {(){;for( = 1; <= 2; = + 1){<<;}}} > Type: output Hardness: 10 // How to enter multiple outputs from alternate lines # 92 Demonstration > {(){;; = 5;for( = 1; <= 2; = + 1){<<;<<;}}} > Type: output Hardness: 10 // --------------------------------------------------------------------------