Question: we have json data that is put into a custom object:

```
 "sentMoney": [
                {
                    "amount": 3840.83,
                    "currency": "MXN",
                    "isMajor": false
                },
                {
                    "amount": 200,
                    "currency": "USD",
                    "isMajor": true
                }
        ]

public final class SentMoney: NSCoding {
  public var currency: String?
  public var isMajor: Bool? = false
  public var amount: Double?
}

```

the custom object is then made reference to in a variable:

```
 public var sentMoney: [SentMoney]?

```

Now what we are trying to do is only get the FIRST amount (3840.83).

I tried doing it this way but there were errors:

```
 let amountsOnlyArray = self.postTransferSuccess?.sentMoney.map({ $0["amount"] })//Error -Cannot subscript a value of type '[SentMoney]' with an index of type 'String' 
 let firstAmountOnly = self.postTransferSuccess?.sentMoney![0]["amount"]//Error -Type 'BSentMoney' has no subscript members

```

Is there a better way to get that first amount?

Answer: 
Don't re-set `isPrime` to true in your second for loop, as soon as the number is not prime once, we know it is not prime forever. Just set it to true once every iteration of the outer loop, and do your final "Is prime" check outside.

```
static void isPrime(int n)
    {
         System.out.println("All the prime numbers up to "+n+" are -->\n");

        for(int i = 2; i <= n; i++)
        {
            boolean isPrime = true;
            for (int j = 2; j < i; j++)
            {

                if(i % j == 0)
                {
                    isPrime = false;
                    System.out.println(i + " is not prime because " + i + " is divisible by " + j );
                    break;
                }
            }
            if (isPrime){
              System.out.println(i + " is prime.");
            }
        }

    }

```

I've added a couple prints to this code so that you can see why each part of the logic is doing what it does -- compare it to your code so that you can understand why yours doesn't actually search for primes.
I think is a logical problem in your script.
You should count with a loop all the number from 2 to n-1 which are = to 0 with a test 

```
n%i = 0

```

If the counter = 0 then no divider then prime number