PHP-language, loops Teppo Räisänen Principal Lecturer Oulu University of Applied Sciences School of Business and Information Management
Loops While For …
Example Print HTML-table using for
While initialization while (condition) { //one or more statemens incrementation }
Example Calculating compound interest using while <? $loan=100; $interest=10; $years=3; $i=0; while ($i < $years) { $loan=$loan+ ($loan / 100) * $interest; $i++; } print ”Total amount of loan is $loan”; ?>
For For (initialization;condition;increment) { //one or more statemens }
Example Calculating compound interest using for <? $loan=100; $interest=10; $years=3; for ($i=0;$i<$years;$i++); { $loan=$loan + ($loan / 100) * $interest; } print ”Total amount of loan is $loan”; ?>