|
-
Jul 21st, 2007, 08:19 AM
#1
Thread Starter
Fanatic Member
Hystograph
Code:
Dim ctr As Integer
Dim i As String
For ctr = 1 To 10
If ctr Mod 2! = 0 Then
Print ctr
End If
Next
Well this is simple how to print an asterisk base on the answer of the if statement. the if statement will output all the even numbers base on the for loop
Last edited by Loraine; Jul 21st, 2007 at 08:58 AM.
-
Jul 21st, 2007, 11:41 PM
#2
Thread Starter
Fanatic Member
Re: Hystograph
When i use the "print ctr" in the if statement the output would be 2,4,6,8,10 but instead of those even numbers the output must be an astersik but base on the number of the even numbers liek [ 2 ** , 4 ****, 6 ******, 8 ******** ]
-
Jul 21st, 2007, 11:45 PM
#3
Re: Hystograph
Hm, try this...
 Originally Posted by Loraine
Code:
Dim ctr As Integer
Dim i As String
For ctr = 1 To 10
If ctr Mod 2! = 0 Then
Print ctr & " " & String(ctr, "*")
End If
Next
Well this is simple how to print an asterisk base on the answer of the if statement. the if statement will output all the even numbers base on the for loop
-
Jul 22nd, 2007, 12:26 AM
#4
Thread Starter
Fanatic Member
Re: Hystograph
It's working but why did you use the
But how if im not using the VB style im using the php how to output a asterisk base on the even numbers
Code:
$ctr = 0;
for ($ctr = 1; $ctr < 10; $ctr++)
{
if ($ctr %2 !==1)
{
echo "$ctr" & "*";
}
}
How about that ?
-
Jul 22nd, 2007, 12:42 AM
#5
Re: Hystograph
 Originally Posted by Loraine
It's working but why did you use the
But how if im not using the VB style im using the php how to output a asterisk base on the even numbers
Code:
$ctr = 0;
for ($ctr = 1; $ctr < 10; $ctr++)
{
if ($ctr %2 !==1)
{
echo "$ctr" & "*";
}
}
How about that ?
That belongs in the PHP forum.
I know some PHP but not aware if PHP has a buil in function like VB's String$() function.
You could write your own:
PHP Code:
<?php
function asterisk($length) {
for($i=1; $i < $length; $i++) {
$ret.= '*';
}
return $ret;
}
for ($ctr = 1; $ctr < 10; $ctr++) {
if ($ctr %2 !==1) {
echo "$ctr " . asterick($ctr);
}
}
?>
-
Jul 22nd, 2007, 12:52 AM
#6
Thread Starter
Fanatic Member
Re: Hystograph
No without using a function just simple as the way you interpret in VB. How simply output the asterisk base on the even numbers. I use the phpjust a sample i can use also the C++. Just to know ohter way to output the asterisk
Code:
PHP:
$ctr = 0;
for ($ctr = 1; $ctr < 10; $ctr++)
{
if ($ctr %2 !==1)
{
echo "$ctr" & "*";
}
}
C++:
int ctr;
for (ctr = 1; ctr < 10; ctr++)
{
if (ctr %2 !==1)
{
cout <<"*";
}
}
i just want to know the other way
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|