Link to home
Start Free TrialLog in
Avatar of ang3lus
ang3lus

asked on

Printing on one line

Hi

I calculate run time of script then depend on this time i create for loop to display progress

for example if execution time 21 seconds the script will print  this shape <> 21 times
<><><><><><><><><><><

my problem is the printing display like this
<
>
<
>
<
>
<
>
<
>
<
>
<
>
<
>
<
>
<
>
How i can avoid line breaking
$time = 9;
for ($i=1; $i -le $time; $i++) {
    $sh1= "<"
     if($i % 2 -eq 0)
     {
      $sh2 = ">"
     }
    $sh1
    $sh2
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rlandquist
rlandquist
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ang3lus
ang3lus

ASKER

Thanks.
It solved my problem
Avatar of GusGallows
You can also add in a sleep timer to make it pop in 1 per second and also print out a blank at the end so your prompt doesn't pop up at the end of your <><><><><>.

It would look as follows:
$time = 9;
for ($i=1; $i -le $time; $i++)
{
	$sh1= "<"
	if($i % 2 -eq 0)
	{
		$sh2 = ">"
	}
	
	start-sleep -s 1
	Write-Host -NoNewline $sh1
	Write-Host -NoNewline $sh2

} 
Write-host

Open in new window