Reputation: 149
var letters: [Character] = ["a", "b", "c", "d"]
for c in letters {
print(c, terminator: "")
}
I am a totally new in swift programming. I use Xcode 9 Beta version. When I compile the code there is no output but if I wrote any thing outside the for a loop the immediately it will show in the output.
Upvotes: 2
Views: 110
Reputation: 12109
The problem is that if you write a print statement without a newline as the terminator, it will only write into a buffer. The buffer is flushed when you print a newline.
To print a newline, just use an empty print()
statement:
var letters: [Character] = ["a", "b", "c", "d"]
for c in letters {
print(c, terminator: "")
}
// Print a newline here, so everything gets flushed.
print()
Upvotes: 2