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 trialSurinder Singh
274 PointsHow to print this pattern in swift code.
Write a program that takes an integer (in a variable) and displays, using asterisks, the figure below. For example, if the input is 5, the program should display.
*
* *
* * *
* * *
* *
*
well , I did this in java but it is little difficult to grab the syntax for me. I want you to explain the code in a proper manner . Thanx in advance
2 Answers
Surinder Singh
274 Pointsi just want to print simply a pattern of stars
*
**
** *
Like this way
Kyle Johnson
33,528 PointsTry this!
func newFunc(someNumber: Int) {
for index in someNumber {
print("*") // There might be a code for the * symbol.
}
}
// Call the function
newFunc(someNumebr: 5)
Kyle Johnson
33,528 PointsKyle Johnson
33,528 PointsCan you answer this question to help me understand your question more.
Do you want a function and takes 1 input parameter (5 in your example) and then prints out a String of asterisks in the shape of a triangle?