Septanet Forum  

Go Back   Septanet Forum > Computers, Software, Harware, Information Technology > PHP Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-08-2011, 03:31 PM   #1
Senior Member
 
sharma.s.prakash's Avatar
 
Join Date: Aug 2011
Posts: 110
Default FOR loop in php

for loop in php with example
for(initilization;condition;steping) {
steps to do;
}
//writting a program to generate a table of an entered number

PHP Code:
$varNumber=5;
//For output on browser
$varLine='<br>'
//For output other than browser
 //$varLine="\n"; 
for($cnt=1;$cnt<=10;$cnt++) {
    
$varResult=$varNumber*$cnt;
    echo 
$varNumber.'X'.$cnt.'='.$varResult.$varLine;

output
5X1=5
5X2=10
5X3=15
5X4=20
5X5=25
5X6=30
5X7=35
5X8=40
5X9=45
5X10=50

another example of for loop by printing the factorial of the number
PHP Code:
$num=5;
$res=1;
for(;
$num>=1;$num--) {
    
$res*=$num;
    if(
$num==1) {
        echo 
$num.'=';
    } else {
        echo 
$num.'X';
    }
}
echo 
$res
output is 5X4X3X2X1=120
sharma.s.prakash is offline  
Digg this Post!Bookmark Post in Technorati
Reply With Quote
Old 05-08-2011, 04:03 PM   #2
Senior Member
 
kaman's Avatar
 
Join Date: Aug 2011
Posts: 111
Default

like it. keep posting...!
kaman is offline  
Digg this Post!Bookmark Post in Technorati
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +5.5. The time now is 12:53 PM.


Content Relevant URLs by vBSEO 3.5.0 RC2