Lab 4 - FL13 - ECE 198 JL - University of Illinois - Engineering Wiki

Rn el ol tefrlo nwiceet i hneii1bcueii teices vleta i

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: , ec + eas + s h nrae au ht s etoe) teeoei=01 hrfr + In ite ra tion 1 ( i nw1 iso ) Tepormte cek wehri<3 h rga hn hcs hte rsl =tu,hnetepormfo ge it telo eut re ec h rga lw os no h op pitHloWrd! rn el ol Tefrlo nwiceet i hnei=i1(bcuei+i teices vleta i mnind h o op o nrmns , ec + eas + s h nrae au ht s etoe) teeoei=11 hrfr + In ite ra tion 2 ( i nw2 iso ) Tepormte cek wehri<3 h rga hn hcs hte rsl =tu,hnetepormfo ge it telo eut re ec h rga lw os no h op pitHloWrd! rn el ol Tefrlo nwiceet i hnei=i1(bcuei+i teices vleta i mnind h o op o nrmns , ec + eas + s h nrae au ht s etoe) teeoei=21 hrfr + In ite ra tion 3 ( i nw3 iso ) Tecmie te pormwehri<3 h oplr hn rga hte rsl =fle hnetepormfo bek oto telo eut as, ec h rga lw ras u f h op Fina l output HloWrd! el ol HloWrd! el ol HloWrd! el ol for (inde x = 0; inde x < m a x _inde x ; inde x + + ) { ... } The above us age of "for" is a time honored way of iterating through integers in the interval [0, max _index ) (0 < = index < max _index ). It's ac tually quite elegant bec aus e the loop ex ec utes ex ac tly "max _index " times (with "index " tak ing values from 0 to max _index - 1). You will s ee it quite often in C c ode and are enc ouraged to us e it y ours elf. T he while loop The while loop does the s ame tas k as the for loop but is us ed when y ou don't k now how many times a partic ular tas k has to be done. Here is a s imple ex ample of the while loop. In this C program, an integer value is entered by the us er. This value then tells our program the number of times "Hello W orld !" has to be printed on the s c reen. This program effec tively does the s ame tas k as the above program if the us er enters 3 #nld<ti.> icuesdoh itmi( n an) { itcut=0 nme_ftms n on , ubro_ie; saf"d,&ubro_ie) cn(%" nme_ftms; wiecut<nme_ftms hl(on ubro_ie) { pit(HloWrd!n) rnf"el ol \"; cut+ on+; } } rtr 0 eun ; As y ou c an s ee for s imple looping operations s uc...
View Full Document

Ask a homework question - tutors are online