Monday, December 15, 2008

Day 3: For Loop, While Loop, And Array for both dimension

Today i am learning the basic structure of loop like for loop and while and do loop

I also learn Switch command

the coding in class is

/*



$a=5;

if($a==5)
{
print "The value of \$a is 5
";
}

else
{
print "The value of \$a is not 5
";
}


($a==6)? print "The value of \$a is 5
" : print "The value of \$a is not 5
";


$a=6;
switch ($a)
{
case 1: print "The value of \$a is 1";
break;

case 2: print "The value of \$a is 2";
break;

case 3: print "The value of \$a is 3";
break;

case 4: print "The value of \$a is 4";
break;

case 5: print "The value of \$a is 5";
break;

default: print "The value of \$a is not in the cases";
break;
}

print "
";
print "
";
print "
";
print "
";
print "
";
print "
";
print "
";

//Loops

print "For Loop:
";
for($i=1; $i<=10; $i++)
{
print "$i
";
}

print "While Loop:
";
$i=1;
while($i<=10)
{
print "$i
";
$i++;
}


print "Do While Loop:
";
$i=1;
do
{
print "$i
";
$i++;
}while($i<=10);


print "Nested Loops:
";


for($i=1; $i<=10; $i++)
{

print "The value of \$i is $i
";

for($j=1; $j<=10; $j++)
{
print "\$j = $j
";
}

}

print "Array:
";


$c= array('a', 'b', 'c', 'd', 'e');

print "$c[3]
";
print "$c[1]
";

$d= array('Hello', 'My', 'Name', 'Is', 'Praful');

print "$d[2]
";


foreach($d as $val)
{

print "$val
";

}

print count($d)."
";


$e= array(name=> 'Innobuzz', course=> 'CPP', time=>'10 - 12');

print "$e[name]
";


foreach($e as $k=> $v)
{

print "$k = $v
";

}


/*Define an array $arr

1: Print the number of elements in arr
2: Print the elements in arr with the positions.

*/










?>
*/

No comments:

Post a Comment