Midwest Dev Chat

MidwestDevChat.com

  • The newest 15 messages in the super-cool #swift channel.

  • 11/29 18:21:18 Myles: i = (i - 9.95) * 1.01 - (9.95) I want to run this for 52 times how would I write that in swift
  • 11/29 18:45:35 Scarlet: Just put it in a for in loop for i in 52 { /* Repeated fifty two times */ }
  • 11/30 11:03:06 Adriene:
    for t in 0..<52 { 
      i = (i - 9.95) * 1.01 - (9.95) 
      print(i) 
    } 
    12448.4505
    12552.935505
    
    // snip
    19355.7257769801
    As an aside, `i` is a popular name for the number of times the loop has run. In the function above, `t` is instead the number of times the loop has run, and `i` is the velocity or the account balance or whatever
  • 11/30 11:04:21 Adriene: personally, I think it never hurts to be super explicit:
    for week in 0..<52 { 
      balance = (balance - 9.95) * 1.01 - (9.95) 
      print(balance) 
    } 
  • 11/30 11:18:45 Adriene: Did you consider simplifying the formula or looking for a different formula that can solve the problem in one iteration instead of 52? > i = (i - 9.95) * 1.01 - (9.95) is equivalent to > i = 1.01 * i - 19.9995 for what it's worth.
  • *Usernames have been changed to protect the innocent.
We're currently 1003 members strong. Join us!
Request Invite

Check out all the cool channels!

Join the conversation!