Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Arrays and Control Structures PHP Loops Do While Looping

Travis John Villanueva
Travis John Villanueva
5,052 Points

how to use the break statement and the new line?

<?php

$currentYear = date('Y');
$year = $currentYear -100;

while($year<=$currentYear){

  echo $year. "<br />\n";
  $year++;

}


?>

I use this code but the interface throws 19....<br />

I expect that the system will throw :

1916
1917
1918

but instead

1916<br />1917<br />

Simon Coates
Simon Coates
28,694 Points

a little confused as to what the problem is. The <br /> should put the year values on new lines in html (what you see via the browser), while the \n is should result in line breaks in the underlying source code (what you'd see via a text editor). The \n will probably be ignored by HTML - which ignores what it regards as blank/white space.

fixed code formatting

2 Answers

The instructor is showing the code on a browser. However, the class so far has been done using the terminal. This is the confusion.

For the student to see what the instructor is showing, they can go into the workspace (instead of their terminal), create the loops.php file in the workspace, enter the code, save it, and then click on the little eye in the upper right, and then select loops.php in the list that appears in the browser window. Doing this will show the years/data in the browser.

I will to show for you some example when you using "</br>\n" this is only to jump one line otherwise if you want to do like this: 1990</br>1998</br> it's will be ignored . the best way is to using like this example that I mentioned yearly for you ...