Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding a tab character in swift

how do you add space in swift?i tried print("\t") but swift seems to ignore the spaces. My code is

var b=1
var a=2

for var i=3;i>=0;i--
{
    for var j=a;j>=0;j--
    {
        print("\t")
    }
    a--

    for var one=1;one<=b;one++
    {
        print("1")

    }
    b++
    println(" ")
}
like image 496
riddl Avatar asked Dec 25 '22 01:12

riddl


2 Answers

I'm just guessing what you are trying to do based on the question and code... Does this do it?

#!/usr/bin/env xcrun swift
for x in 1 ... 4 {
    for y in 0 ..< 4 - x {
        print(" ")
    }
    for y in 0 ..< x {
        print("1")
    }
    print("\n")
}

The above code outputs:

   1
  11
 111
1111
like image 42
Daniel T. Avatar answered Feb 08 '23 18:02

Daniel T.


The question is confusing, but rest assured in Swift 3, this will print a tab:

print("\t")
like image 131
mcfroob Avatar answered Feb 08 '23 19:02

mcfroob